我使用了devise来集成用户注册和登录。现在我也忘记了密码页面。
将用户电子邮件从登录表单上的user_email文本字段传递到忘记密码表单的最佳方法是什么,这样用户不需要两次输入他/她的电子邮件?< / p>
链接到忘记密码页面:
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
登录表单:
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, :required => true %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off", :required => true %></div>
<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
<% end -%>
<div><%= f.submit "Sign in" %></div>
<% end %>
忘记密码表格:
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %></div>
<div><%= f.submit "Send me reset password instructions" %></div>
<% end %>
答案 0 :(得分:0)
试试这个
<%= f.email_field :email, autofocus: true, object: resource %></div>