0
votes

I'm following the railscast for omniauth pretty closely but I'm getting this error that is not experienced in the video

Can't mass-assign protected attributes: provider, uid

Here's the authentication controller that I created

class AuthenticationsController < InheritedResources::Base

def index
    @authentications = current_user.authentications if current_user
end

def create
  omniauth = request.env['omniauth.auth']
  authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
  if authentication
     flash[:notice] = "Signed in successfully"
     sign_in_and_redirect(:user, authentication.user)
  elsif current_user
   current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
   flash[:notice] = "Authentication successful"
   redirect_to authentications_url
   else
    user = User.new
    user.apply_omniauth(omniauth)
    user.save(:validate=>false)
    flash[:notice] = "Signed in successfully"
     sign_in_and_redirect(:user, user)
end
end

def destroy
    @authentication = current_user.authentications.find(params[:id])
    @authentication.destroy
    flash[:notice] = "Successfully destroyed authentication"
    redirect_to authentications_url

end
end

Here's what I have for user.rb where I have added :provider and :uid to attr_accessible after looking at past threads

class User < ActiveRecord::Base

  attr_accessible :name, :email, :password, :password_confirmation, :provider, :uid
  has_many :authentications

Unfortunately, I'm still getting this error when I try to login using Twitter (path = /auth/twitter/callback)

1
you should add provider and uid in Authentication model because u call method create! on this model - Eru
now it gives a private method apply_twitter' called` error on that same controller.. do you know why? - johbones
maybe the method is private and you call it from other model - Eru

1 Answers

0
votes

You should add

attr_accessible :provider, :uid

in the Authentications model and not in User model.

(As those are attributes of authentications model and you are mass assigning it in a authentications model)