铁轨和设计:两步确认参数错误

发布于 2024-11-19 10:04:09 字数 2363 浏览 5 评论 0原文

这是我的灾难和戏剧的延续......

贯穿:

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:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木森分化 2024-11-26 10:04:10

问题似乎在于使用 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文