为什么我无法在 Rails 3 中使用此参数创建?
我有一个带有以下行的方法:
26 User.create!(:email => "[email protected]", :linkedin_uid => linkedin_uid, :password => Devise.friendly_token[0,20])
这是我的控制器:
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
即使在 Rails 控制台中,当我尝试通过传递 params :linkedin_uid 来创建它时,它仍然显示为零。 :(
这是该行的上下文:
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 => "[email protected]", :linkedin_uid => linkedin_uid, :password => Devise.friendly_token[0,20])
27 end
28 end
I have a method with the following line:
26 User.create!(:email => "[email protected]", :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. :(
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 => "[email protected]", :linkedin_uid => linkedin_uid, :password => Devise.friendly_token[0,20])
27 end
28 end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设这是来自 Devise 的用户模型。这里的问题可能是您还没有创建
linkedin_uid
mass-可分配。您需要在您的User
模型中通过以下方式执行此操作:每当您使用 attr_accessible 定义字段时,这些字段将成为唯一将通过 批量分配 函数。
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 yourUser
model viaWhenever you defined fields with attr_accessible those become the ONLY fields that will be updated via mass assignment functions.
检查数据库中 linkedin_uid 列的数据类型,以确保它可以支持您在 create 方法中提供的数据。
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.