RailsCasts Pro episodes are now free!

Learn more or hide this

venkatnr's Profile

GitHub User: venkatnr

Comments by

Avatar

Hi every one.. if iam using mongoid(mongo database for creating user) with out having devise gem on it.. how can i find current user.

rails g model user provider uid name oauth_token oauth_expires_at:datetime
invoke mongoid
create app/models/user.rb
invoke test_unit
create test/unit/user_test.rb
create test/fixtures/users.yml

this is way i created user model, in model, i change the code like...

class User
include Mongoid::Document

def self.from_omniauth(auth)
auth.slice(:provider, :uid) do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name

user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!

end
end
end

in application.html.erb file how i need to get current user.. here we are using current_user right but if iam raise that, iam getting nill is current user.