开发者

DEVISE - successful message when ask for a new password

开发者 https://www.devze.com 2023-03-21 22:11 出处:网络
I\'m using the Devise gem and I just would like to show a successful message when someone ask for a new password (if forgotten). Currently, when submitted, the button redirects to sign_in without any

I'm using the Devise gem and I just would like to show a successful message when someone ask for a new password (if forgotten). Currently, when submitted, the button redirects to sign_in without any mes开发者_Go百科sage.

Thank you


Rather than using the flash and trying to work out how Devise does it's thing (not for the faint-hearted) by extending its controllers, how about checking the referrer, and displaying a message in the view if it matches your 'remind me of my password' path?

In the view:

<% if request.env['HTTP_REFERER'] == "/give/me/a/new/password" %>
  <h2>Your password stuff is all good now.</h2>
<% end %>


flash[:success] = "Something Something"


Devise rolls out it's own alert messages (and they can be edited in the config/locales/devise.en.yml and written for other languages), you just need to catch them.

One way is to add a layout/_messages partial:

<% flash.each do |name, msg| %>
  <% if msg.is_a?(String) %>
    <div class="alert alert-<%= name %>">
      <a class="close" data-dismiss="alert">&#215;</a>
      <%= content_tag :div, msg, :id => "flash_#{name}" %>
    </div>
  <% end %>
<% end %>

and render it in application.html.erb:

<%= render 'layouts/messages' %>

This has the benefit of catching all (devise and other) messages and playing nicely with bootstrap alert classes (if you use were using bootstrap).

.

Or if you are using slim:

- flash.each do |name, msg|
  - if msg.is_a?(String)
    div class="alert alert-#{name}"
      a class="close" data-dismiss="alert"
        | &#215;
      = content_tag :div, msg, :id => "flash_#{name}"

= render 'layouts/messages'

.

Devise uses the rails standard :notice rather than :success but a you can add the success (green) styling to your css/scss (e.g. to bootstrap_and_overriders.css.scss):

.alert-alert {
  @extend .alert-error
}
.alert-notice {
  @extend .alert-success
}
0

精彩评论

暂无评论...
验证码 换一张
取 消