1

这是我的痛苦和戏剧的延续......

跑过,匆匆处理:

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 !@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

这是我的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 新手!

4

1 回答 1

1

问题似乎在于使用User.find(params[:user][:confirmation_token]).

这是因为该find()方法将通过 ID 查找用户。使用不同的方法通过确认令牌找到用户应该返回正确的用户。在 show 动作中,您已经使用过此方法一次。

希望这是最后一个问题!

于 2011-07-07T14:54:49.220 回答