Ruby on rails 在rails中的忘记密码方法中访问用户

Ruby on rails 在rails中的忘记密码方法中访问用户,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.1,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 3.1,我在使用forgotpassword方法访问用户的电子邮件时遇到问题。如何在不使用此方法创建新用户的情况下访问电子邮件。我已经在users.rb模型中发送了新的密码方法 def forgot_password if request.post? user = User.find_by_email(params[:user][:email]) puts user if user and user.send_new_password flas

我在使用forgotpassword方法访问用户的电子邮件时遇到问题。如何在不使用此方法创建新用户的情况下访问电子邮件。我已经在users.rb模型中发送了新的密码方法

def forgot_password
    if request.post?
      user = User.find_by_email(params[:user][:email])
      puts user
      if user and user.send_new_password
        flash[:message]  = "A new password has been sent by email."
       # redirect_to root_path
      else
        flash[:warning]  = "Couldn't send password"
      end
    end
  end
这是我忘记密码的页面

<h1>Forgot Password</h1>
<%= form_for(@user) do |f| %>
  <%= render 'shared/error_messages', :object => f.object %>
    <div class="field">
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </div>
<div class="actions">
    <%= f.submit "Submit" %>
  </div>
<% end %>
忘记密码
f、 对象%>


您可能想做

form_for(User.new)

由于您没有任何对象可放入
@user

中,请更具体一些。什么时候发生的?是在呈现表单时,还是在提交表单时?日志中有错误吗?尝试添加日志消息以了解错误发生的位置。