Skip to content

Instantly share code, notes, and snippets.

View abhishek0's full-sized avatar

Abhishek Sharma abhishek0

  • Snapstick Inc.
View GitHub Profile
class LoginController < ApplicationController
skip_before_filter :check_authentication, :only => :index
def index
user = User.find_by_email(params[:email])
if user and user.authenticate(params[:password])
respond_with user
end
end
class LoginController < ApplicationController
skip_before_filter :check_authentication, :only => :index
def index
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
respond_with user
else
render
end
class LoginController < ApplicationController
skip_before_filter :check_authentication, :only => :index
def index
@user = User.find_by_email(params[:email])
if @user && @user.authenticate(params[:password])
render 'login/index'
else
record_not_found
end
{
"user" : {
"first_name": "John",
"last_name": "Doe",
"email": "[email protected]",
"mobile": "9876545678",
"locality": "Goregaon",
"city": "Mumbai",
"user_type": "advisor",
}
class CreateInquiries < ActiveRecord::Migration
def change
create_table :inquiries, id: false do |t|
t.primary_key :id, :uuid, :default => 'uuid_generate_v1()'
t.belongs_to :contact
t.string :inquiry_type
t.hstore :metadata
t.string :locality
t.string :city
t.uuid :added_by
module Contactable
def self.set_contact(contact)
@contact = Contact.find_by_email(contact[:email])
@contact = Contact.create!(contact) unless @contact.exists?
end
def self.get_contact
@contact
end
end
require 'spec_helper'
require 'faker'
describe Stampable do
it "throws error if stamp and contact is unset" do
expect { FactoryGirl.create(:user) }.to raise_error
end
it "can be saved if contact and stamp were set" do
user = FactoryGirl.build(:user)
require 'spec_helper'
describe UsersController do
render_views
describe 'franchisee actions on users' do
before :each do
fr = FactoryGirl.build(:user, user_type: 'franchisee')
fr.set_stamp(FactoryGirl.build(:stamp), FactoryGirl.build(:contact, email: '[email protected]'))
fr.save
@abhishek0
abhishek0 / ar_q.rb
Last active December 21, 2015 01:19
User.includes(stamp: [:contact]).where(:user_type => 'franchisee').joins(:stamp).joins(:children).group("users.id, stamps.status").count("stamps.status")
users = Arel::Table.new(:users)
stamps = Arel::Table.new(:stamps)
contacts = Arel::Table.new(:contacts)
children = users.alias
query = users.where(users[:user_type].eq('franchisee'))
query = query.join(stamps).on(users[:id].eq(stamps[:stampable_id]))
query = query.join(contacts).on(contacts[:id].eq(stamps[:contact_id]))
query = query.join(children).on(users[:id].eq(children[:parent_id]))
query = query.join(stamps).on(children[:id].eq(stamps[:stampable_id]))