当用户点击忘记密码时,它会将他们带到忘记密码页面,其中有一个字段供他们输入他们的电子邮件地址。如果他们的电子邮件地址在数据库中,一切都很好,但如果数据库中不存在该电子邮件地址,它只会重定向到同一页面,但不会显示错误消息。
如何让错误消息出现?
/view/devise/passwords/new.html.erb
...
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
<h1>Reset Password</h1>
<div class="login-fields">
<p>Instructions on resetting your password will be emailed to you.</p>
<%= render :partial => '/shared/messages' %>
<div class="field">
<%= f.label :email %>
<%= f.email_field :email, :placeholder => 'Email', :class => 'login username-field' %>
</div> <!-- /field -->
</div> <!-- /login-fields -->
<div class="login-actions">
<%= content_tag(:button, :type=>:submit, :class => "button btn btn-secondary btn-large") do %>
Send me reset password instructions
<% end %>
</div> <!-- .actions -->
<div class="login-social">
<%= render "devise/shared/links" %>
</div>
<% end %>
...
/views/shared/_messages.html.erb
<% if alert || flash[:alert] || flash[:error] %>
<div class="alert alert-error">
<a class="close" data-dismiss="alert" href="#">x</a>
<h4 class="alert-heading">Error!</h4>
<%= alert %>
<%= flash[:error] %>
</div>
<% end %>
<% if flash[:success] || notice || flash[:notice]%>
<div class="alert alert-success">
<a class="close" data-dismiss="alert" href="#">x</a>
<h4 class="alert-heading">Success!</h4>
<%= flash[:success] %>
<%= notice %>
</div>
<% end %>