开发者

why am I not able to create with this parameter in Rails 3?

开发者 https://www.devze.com 2023-02-19 23:26 出处:网络
I have a method with the following line: 26User.create!(:email => \"token@email.com\", :linkedin_uid => linkedin_uid, :password => Devise.friendly_token[0,20])

I have a method with the following line:

26         User.create!(:email => "token@email.com", :linkedin_uid => linkedin_uid, :password => Devise.friendly_token[0,20]) 

Here is my controller:

20   def create
 21     @user = User.new(params[:user])
 22     if @user.save
 23       flash[:notice] = "Successfully created user."
 24       redirect_to @user
 25     else
 26       render :action => 'new'
 27     end
 28   end

Even from the rails console when I try to create it by passing the params :linkedin_uid, it still comes out nil. 开发者_如何学C:(

Here is the context for the line:

18   def self.find_for_linked_in_oauth(omniauth_hash, signed_in_resource=nil)
 19     debugger
 20     #omniauth_hash is a hash passed in from env["omniauth_hash"] by callback controller
 21     linkedin_uid = omniauth_hash['uid']
 22       debugger
 23       if user = User.find_by_linkedin_uid(linkedin_uid)
 24         user
 25       else # Create an user with a stub password. 
 26         User.create!(:email => "token@email.com", :linkedin_uid => linkedin_uid, :password => Devise.friendly_token[0,20]) 
 27       end
 28   end


I am assuming that this is a User model from Devise. The problem here is likely that you haven't made linkedin_uid mass-assignable. You will need to do that in your User model via

attr_accessible :linkedin_uid

Whenever you defined fields with attr_accessible those become the ONLY fields that will be updated via mass assignment functions.


Check your data type for the linkedin_uid column in the database to make sure it can support the data you are giving it in the create method.

0

精彩评论

暂无评论...
验证码 换一张
取 消