Skip to content

Instantly share code, notes, and snippets.

View abhishek0's full-sized avatar

Abhishek Sharma abhishek0

  • Snapstick Inc.
View GitHub Profile
@abhishek0
abhishek0 / request
Created August 8, 2013 19:33
Simple mongoid models and creation controllers
curl http://localhost:3000/users -d "{'user': {'firstName': 'Abhishek', 'loginInfo':{'password':'p'}}}"
class ApplicationController < ActionController::Base
before_action :require_login
private
def check_user
if not request.headers["user_id"].empty?
def self.get_user
Users.get({id => request.headers["user_id"]})
end
@abhishek0
abhishek0 / seed.rb
Created August 9, 2013 09:38
Many to one on same mongoid collection
admin = User.create! :first_name => 'admin', :last_name => 'admin', :email => '[email protected]', :mobile => '9999911111', :locality => 'Goregaon', :city => 'Mumbai', :user_type => 'admin', :username => '[email protected]', :password => 'admin'
franchisee = User.create! :first_name => 'franchisee', :last_name => 'franchisee', :email => '[email protected]', :mobile => '9999911111', :locality => 'Goregaon', :city => 'Mumbai', :user_type => 'franchisee', :username => '[email protected]', :password => 'franchisee'
franchisee.parent = admin
franchisee.save!
** Invoke db:seed (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:seed
Default users
rake aborted!
undefined method `push' for nil:NilClass
/home/abhishek/.rvm/gems/jruby-1.7.4/bundler/gems/mongoid-85e146637503/lib/mongoid/relations/bindings/referenced/in.rb:29:in `bind_one'
/home/abhishek/.rvm/gems/jruby-1.7.4/bundler/gems/mongoid-85e146637503/lib/mongoid/relations/binding.rb:38:in `binding'
/home/abhishek/.rvm/gems/jruby-1.7.4/bundler/gems/mongoid-85e146637503/lib/mongoid/threaded/lifecycle.rb:55:in `_binding'
Default users
rake aborted!
undefined method `<<' for nil:NilClass
/home/abhishek/mine/code/infocus/backend-ror/db/seeds.rb:10:in `(root)'
org/jruby/RubyKernel.java:1073:in `load'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:1:in `(root)'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
org/jruby/RubyProc.java:255:in `call'
Default users
rake aborted!
undefined method `<<' for nil:NilClass
/home/abhishek/mine/code/infocus/backend-ror/db/seeds.rb:10:in `(root)'
org/jruby/RubyKernel.java:1073:in `load'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:1:in `(root)'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
org/jruby/RubyProc.java:255:in `call'
Default users
rake aborted!
undefined method `push' for nil:NilClass
/home/abhishek/.rvm/gems/jruby-1.7.4/bundler/gems/mongoid-85e146637503/lib/mongoid/relations/bindings/referenced/in.rb:29:in `bind_one'
/home/abhishek/.rvm/gems/jruby-1.7.4/bundler/gems/mongoid-85e146637503/lib/mongoid/relations/binding.rb:38:in `binding'
/home/abhishek/.rvm/gems/jruby-1.7.4/bundler/gems/mongoid-85e146637503/lib/mongoid/threaded/lifecycle.rb:55:in `_binding'
/home/abhishek/.rvm/gems/jruby-1.7.4/bundler/gems/mongoid-85e146637503/lib/mongoid/relations/binding.rb:37:in `binding'
/home/abhishek/.rvm/gems/jruby-1.7.4/bundler/gems/mongoid-85e146637503/lib/mongoid/relations/bindings/referenced/in.rb:22:in `bind_one'
/home/abhishek/.rvm/gems/jruby-1.7.4/bundler/gems/mongoid-85e146637503/lib/mongoid/relations/proxy.rb:25:in `bind_one'
/home/abhishek/.rvm/gems/jruby-1.7.4/bundler/gems/mongoid-85e146637503/lib/mongoid/relations/referenced/in.rb:25:in `initialize'
class CreateUsers < ActiveRecord::Migration
def change
create_table :users, id: false do |t|
t.primary_key :id, :uuid, :default => 'uuid_generate_v1()'
t.string :first_name
t.string :last_name
t.string :email
t.string :mobile_number
t.string :locality
t.string :city
class CreateUsers < ActiveRecord::Migration
def change
enable_extension 'uuid-ossp'
create_table :users, id: false do |t|
t.primary_key :id, :uuid, :default => 'uuid_generate_v1()'
t.string :first_name
t.string :last_name
t.string :email
t.string :mobile_number
t.string :locality
class LoginController < ApplicationController
skip_before_filter :check_authentication, :only => :index
def index
respond_with User.where(login_params)
end
private
def login_params
params.permit(:email, :password)