Railsでパスワードを忘れた場合のソリューションを実装しようとしています。ユーザーが登録済みアカウントの電子メール アドレスを入力するためのフォームがあり、パスワード リセット ページにリンクする一意の 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の両方に対してビューとコントローラー関数を定義しているので、なぜこのルーティング エラーが発生するのか不思議です。
2 つの質問があります。
- パス、メソッド、およびビューが明確に定義されているのに、ActionController でこのエラーが発生するのはなぜですか?
- 他の誰かが RoR でパスワードのリセットを実装しましたか? このアプローチが良い方法であるかどうかについて、洞察を与えることができますか?
前もって感謝します!