【发布时间】:2011-08-28 17:45:22
【问题描述】:
我正在尝试在 Rails 中实现忘记密码的解决方案。我有一个表格供用户输入其注册帐户的电子邮件地址,并且我打算让邮寄者通过电子邮件向他们发送一个唯一的 URL,该 URL 将他们链接到密码重置页面。
我的 config/routes.rb 文件有以下路由:
resources :users do
collection do
get :lost_password #the account-email submisison form url
get :reset_password #a url for the function that sends the response email
end
end
当我从控制台运行 rake routes 时,我得到了我想要的路径:
lost_password_users GET /users/lost_password(.:format) {:action=>"lost_password", :controller=>"users"}
reset_password_users GET /users/reset_password(.:format) {:action=>"reset_password", :controller=>"users"}
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
但是!当用户点击下面代码中概述的表单上的提交按钮时:
<h3>Reset Password</h3>
<%= form_for(:user, :url => reset_password_users_path) do |f| %>
<p>Enter the email address you used to register for this site.</p></br>
<div class="field">
<%= f.label :email %> </br>
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit "Send Email" %>
</div>
<% end %>
我得到一个
没有路线匹配 "/users/reset_password"
通过 ActionController 出错。
事实上,我确实为 lost_password_users_path 和 reset_password_users_path 定义了视图和控制器函数,所以我很困惑为什么会遇到这种情况路由错误。
我有两个问题:
- 当我明确定义了路径、方法和视图时,为什么 ActionController 会引发此错误?
- 是否有其他人在 RoR 中实施了密码重置,您能否就这种方法是否是好的做法提供任何见解?
提前致谢!
【问题讨论】:
标签: ruby-on-rails-3 rails-routing forgot-password