This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
has_many :comments | |
end | |
class Comment < ActiveRecord::Base | |
belongs_to :post | |
end | |
post = Post.first |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@result = [] | |
def flatten_it(array) | |
array.each do |element| | |
element.is_a?(Array) ? flatten_it(element) : @result << element | |
end | |
end | |
flatten_it([[1,2,[3]],4]) | |
puts @result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#View Original : https://github.com/plataformatec/devise/blob/master/app/controllers/devise/sessions_controller.rb | |
class Users::SessionsController < Devise::SessionsController | |
respond_to :json | |
# POST /resource/sign_in | |
def create | |
self.resource = warden.authenticate!(auth_options) | |
set_flash_message(:notice, :signed_in) if is_flashing_format? | |
sign_in(resource_name, resource) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#View original : https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb | |
class Users::RegistrationsController < Devise::RegistrationsController | |
respond_to :json | |
# POST /resource | |
def create | |
build_resource(sign_up_params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) ActiveModel validation in rails server side : | |
class MyObject < ActiveRecord::Base | |
validates :state, :presence => true | |
validates :other_state, :presence => true, if: state.persent? | |
end | |
2) Lets say we have drop down with following state : | |
<select id="stateDropdown" name="state"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: nginx | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: starts the nginx web server | |
# Description: starts nginx using start-stop-daemon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes 1; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
passenger_root /path/to/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.24; | |
passenger_ruby /path/to/.rvm/gems/ruby-2.3.0/wrappers/ruby; | |
include mime.types; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.healthseva.widget; | |
import com.healthseva.R; | |
import com.healthseva.services.RandomTipService; | |
import com.healthseva.utility.ServiceUtility; | |
import android.app.PendingIntent; | |
import android.appwidget.AppWidgetManager; | |
import android.appwidget.AppWidgetProvider; | |
import android.content.ComponentName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def initialize(thing) | |
@thing = thing | |
end | |
def test_me | |
if @thing.big? | |
'Big!' | |
else | |
'Small!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(document).ready(function(){ | |
var startRecording = document.getElementById('start-recording'); | |
var stopRecording = document.getElementById('stop-recording'); | |
var uploadRecordingBtn = document.getElementById('upload-recording'); | |
var cameraPreview = document.getElementById('camera-preview'); | |
NewerOlder