RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: raybesiga
Site: http://raybesiga.com
Hey guys,
I followed the tutorial precisely but I am getting an error such as this:
NoMethodError in SessionsController#create
undefined method `slice` for nil:NilClass
Rails.root: /Users/raybesiga/Documents/Sites/foodie Application Trace | Framework Trace | Full Trace
app/models/user.rb:29:in from_omniauth' app/controllers/sessions_controller.rb:3:increate'
from_omniauth' app/controllers/sessions_controller.rb:3:in
However my user.rb file is as below:
class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :provider, :uid validates_presence_of :name validates_uniqueness_of :name, :email, :case_sensitive => false # attr_accessible :title, :body def self.from_omniauth(auth) where(auth.slice(:provider, :uid)).first_or_initialize.tap 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
and my sessions_controller.rb file is as follows:
class SessionsController < ApplicationController def create user = User.from_omniauth(env["ominauth.auth"]) # session[:user_id] = user.user_id session[:user_id] = user.id redirect_to root_url end def destroy session[:user_id] = nil redirect_to root_url end end
Any idea why I get this error?
Hey guys,
I followed the tutorial precisely but I am getting an error such as this:
NoMethodError in SessionsController#create
Rails.root: /Users/raybesiga/Documents/Sites/foodie
Application Trace | Framework Trace | Full Trace
app/models/user.rb:29:in
from_omniauth'
create'app/controllers/sessions_controller.rb:3:in
However my user.rb file is as below:
and my sessions_controller.rb file is as follows:
Any idea why I get this error?