ruby on rails - Devise+OmniAuth for Facebook Sign Up on Remote Server -
i using devise + omniauth enable facebook signup in application. when developing it, encountered no problems. same deploying remote server. problem is, other people keep encountering same error:
typeerror (no implicit conversion of symbol integer): app/models/user.rb:67:in `find_for_facebook_oauth' app/controllers/users/omniauth_callbacks_controller.rb:4:in `facebook'
i have following code user model user.rb
:
def self.find_for_facebook_oauth( data, signed_in_resource=nil) user = user.where(:email => data.info.email).first unless user params = { :user => { :username => data.uid, :email => data.info.email, :password => devise.friendly_token[0,20], :user_profile_attributes => { :first_name => data.extra.raw_info.first_name, :last_name => data.extra.raw_info.last_name, :remote_image_url => data.extra.raw_info.image, }, :user_auths_attributes => { :uid => data.uid, :provider => data.provider } } } user = user.create!(params[:user]) end return user end
where line 67 user = user.create!(params[:user])
and omniauth_callbacks_controller.rb
:
def facebook # need implement method below in model (e.g. app/models/user.rb) @user = user.find_for_facebook_oauth(request.env["omniauth.auth"]) if @user.persisted? sign_in_and_redirect @user, :event => :authentication #this throw if @user not activated set_flash_message(:notice, :success, :kind => "facebook") if is_navigational_format? else session["devise.facebook_data"] = request.env["omniauth.auth"] redirect_to new_user_registration_url end end
where line 4 @user = user.find_for_facebook_oauth(request.env["omniauth.auth"])
the server logs show parameters:
parameters: {"code"=>"[some long string of number , letters]", "state"=>"[another string of numbers , letters]"}
update: logger outputs following request.env["omniauth.auth"]
:
#<omniauth::authhash credentials=#<omniauth::authhash expires=true expires_at=1401992074 token="*"> extra=#<omniauth::authhash raw_info=#<omniauth::authhash email="*" first_name="*" gender="male" id="*" last_name="*" link="https://www.facebook.com/*" locale="en_us" name="*" timezone=8 updated_time="2014-04-05t09:29:22+0000" username="*" verified=true>> info=#<omniauth::authhash::infohash email="*" first_name="*" image="http://graph.facebook.com/*/picture?type=square" last_name="*" name="*" nickname="*" urls=#<omniauth::authhash facebook="https://www.facebook.com/*"> verified=true> provider="facebook" uid="*">
update 2: logging params[:user] provides following values:
params: {:username=>"*", :email=>"*", :password=>"iepvlt7xewk4ywpjja6n", :user_profile_attributes=>{:first_name=>"*", :last_name=>"*", :remote_image_url=>"http://graph.facebook.com/*/picture?type=square"}, :user_auths_attributes=>{:uid=>"*", :provider=>"facebook"}}
update params hash below:
params = { :user => { :username => data.uid, :email => data.info.email, :password => devise.friendly_token[0,20], :user_profile_attributes => { :first_name => data.extra.raw_info.first_name, :last_name => data.extra.raw_info.last_name, :remote_image_url => data.info.image ## removed comma , updated method }, :user_auths_attributes => [{ :uid => data.uid, :provider => data.provider }] ## enclosed within array [] brackets } }
looking @ params hash given you, can tell user
, profile
have 1-1 relationship
whereas user
, auths
has 1-m relationship
. in case, user_auths_attributes
must passed array
.
typeerror (no implicit conversion of symbol integer)
you getting above error because user_auths_attributes
being interpreted array , not hash. when ruby saw params[:user][:user_auths_attributes][:uid] trying take last key , turn params[:user][:user_auths_attributes][0] or @ least find integer value converted index array.
Comments
Post a Comment