铁轨和设计:两步确认参数错误
这是我的灾难和戏剧的延续......
贯穿:
- 我可以输入我的电子邮件来注册!
- 我可以点击确认链接!
我被带到正确的页面进行确认:
<块引用>http://localhost:3000/user/confirmation?confirmation_token=jxOZQnyixE1PvnrptnYO
问题是……一旦我提交了表格,我就得到了这个错误:
ActiveRecord::RecordNotFound in ConfirmationsController#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 [email protected]?
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
这是我的 show.html.erb
<%= 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 %>
我已经为此哭泣了一个星期......我真的希望这是我的一个愚蠢的错误(同时我也没有)。
如果您需要,我很乐意为您提供更多信息。为了方便起见,您能否详细描述一下您的答案——我是 Rails 新手!
This is a continuation of my woes and drama ...
Run through:
- I can enter my email to register!
- I can click the confirmation link!
I'm taken to the correct page to confirm:
http://localhost:3000/user/confirmation?confirmation_token=jxOZQnyixE1PvnrptnYO
Here's the problem...once I submit the form, I get this error:
ActiveRecord::RecordNotFound in ConfirmationsController#confirm_account
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"qUk6EDoR6N+V0h5O/jLKNZtl0hiaN/g9Gd5YdI2QhIU=",
"user"=>{"confirmation_token"=>"jxOZQnyixE1PvnrptnYO",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]"},
"commit"=>"Confirm Account"}
The problem is in line 10:
class ConfirmationsController < Devise::ConfirmationsController
def show
@user = User.find_by_confirmation_token(params[:confirmation_token])
if [email protected]?
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
Here's my show.html.erb
<%= 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 %>
I've been crying about this for a week...I really hope this is a moronic mistake on my part (and at the same time I don't).
I'll be happy to provide you with more information if you need it. For my convenience, could you describe your answers throughly--I'm a rails newbie!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎在于使用
User.find(params[:user][:confirmation_token])
查找用户。这是因为
find()
方法将通过 ID 查找用户。使用不同的方法通过确认令牌查找用户应该返回正确的用户。在显示操作中,您已经使用过此方法一次。希望这是最后一个问题!
The problem seems to be in finding the user with
User.find(params[:user][:confirmation_token])
.This is because the
find()
method will look for a user by ID. Using a different method to find the user by confirmation token should return the right user. In the show action you already used this method once.Hopefully this is the last problem!