Ruby on rails 铁路及;设计:两步确认参数错误
这是我的 贯穿:Ruby on rails 铁路及;设计:两步确认参数错误,ruby-on-rails,rails-activerecord,registration,confirmation,Ruby On Rails,Rails Activerecord,Registration,Confirmation,这是我的 贯穿: 我可以输入我的电子邮件进行注册 我可以点击确认链接 我被带到正确的页面确认: 问题是……一旦我提交表单,就会出现以下错误: ActiveRecord::RecordNotFound in confirmationcontroller#confirm_account {"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"qUk6EDoR6N+V0h5O/jLKNZtl0hiaN/g9Gd5Y
- 我可以输入我的电子邮件进行注册李>
- 我可以点击确认链接李>
- 我被带到正确的页面确认:
- 问题是……一旦我提交表单,就会出现以下错误:
ActiveRecord::RecordNotFound in confirmationcontroller#confirm_account
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"qUk6EDoR6N+V0h5O/jLKNZtl0hiaN/g9Gd5YdI2QhIU=",
"user"=>{"confirmation_token"=>"jxOZQnyixE1PvnrptnYO",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]"},
"commit"=>"Confirm Account"}
问题在第10行:
class ConfirmationsController < Devise::ConfirmationsController
def show
@user = User.find_by_confirmation_token(params[:confirmation_token])
if !@user.present?
render_with_scope :new
end
end
def confirm_account
@user = User.find(params[:user][:confirmation_token])
if @user.update_attributes(params[:user]) and @user.password_match?
@user = User.confirm_by_token(@user.confirmation_token)
set_flash_message :notice, :confirmed
sign_in_and_redirect("user", @user)
else
render :action => "show"
end
end
end
我已经为此哭了一个星期了……我真的希望这是我犯的一个愚蠢的错误(同时我也不希望)
如果你需要的话,我很乐意为你提供更多的信息。为了我的方便,你能完整地描述一下你的答案吗?我是rails的新手 问题似乎在于使用
user.find(params[:user][:confirmation\u token])
查找用户
这是因为find()
方法将按ID查找用户。使用其他方法通过确认令牌查找用户应返回正确的用户。在show action中,您已经使用过此方法一次
希望这是最后一个问题 问题似乎在于使用
user.find(params[:user][:confirmation\u token])
查找用户
这是因为find()
方法将按ID查找用户。使用其他方法通过确认令牌查找用户应返回正确的用户。在show action中,您已经使用过此方法一次
希望这是最后一个问题 我有点理解。我需要找到一个用户,其中confirmation\u token=>:confirmation\u token,或者其他什么,对吗???就像我说的,我是个新手。如果你能扩展我会很高兴的。除了“查找”之外,还有其他方法可以使用吗?是的!我可以告诉你,但我想你应该自己找。使用与show action相同的方法,其中显示@user=find…噢…我的天哪。我在这上面花了很长时间。我想这就是你学习的方式非常感谢!恭喜你!为了便于将来参考,使用ActiveRecord的任何记录都可以使用find_by_something()方法。我有点理解。我需要找到一个用户,其中confirmation\u token=>:confirmation\u token,或者其他什么,对吗???就像我说的,我是个新手。如果你能扩展我会很高兴的。除了“查找”之外,还有其他方法可以使用吗?是的!我可以告诉你,但我想你应该自己找。使用与show action相同的方法,其中显示@user=find…噢…我的天哪。我在这上面花了很长时间。我想这就是你学习的方式非常感谢!恭喜你!为了便于将来参考,使用ActiveRecord的任何记录都可以使用find_by_something()方法。
<%= form_for(resource, :url => confirm_account_path) do |f| %>
<%= f.label :email %>
<%= @user.email %>
<%= f.hidden_field :confirmation_token %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
<%= f.submit 'Confirm Account' %>
<%= link_to 'Home', root_url %>
<%= render :partial => 'devise/shared/links' %>
<% end %>