【问题标题】:DEVISE - successful message when ask for a new password设计 - 要求输入新密码时的成功消息
【发布时间】:2011-07-20 12:46:02
【问题描述】:

我正在使用 Devise gem,我只想在有人要求输入新密码时显示成功消息(如果忘记了)。目前,当提交时,按钮会重定向到 sign_in 而没有任何消息。

谢谢

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 devise gem


    【解决方案1】:

    与其使用闪光灯并尝试通过扩展其控制器来弄清楚 Devise 是如何做到的(不适合胆小的人),不如检查引荐来源,并在视图中显示一条消息(如果它符合您的“提醒”)我的密码路径?

    在视图中:

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

    【讨论】:

    • 对不起,我是 stackoverflow 的新手
    【解决方案2】:

    flash[:success] = "某事某事"

    【讨论】:

    • 这需要在设计控制器上进行定制。如果有,请发布该代码。
    • 好的,谢谢!但是我必须覆盖哪个控制器?密码控制器?我很迷茫:/
    【解决方案3】:

    Devise 推出了它自己的警报消息(可以在 config/locales/devise.en.yml 中编辑它们并为其他语言编写),您只需抓住它们。

    一种方法是添加 layout/_messages 部分:

    <% 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 %>
    

    并在application.html.erb中渲染它:

    <%= render 'layouts/messages' %>
    

    这样做的好处是可以捕获所有(设计和其他)消息,并且可以很好地使用引导警报类(如果您使用的是引导程序)。

    .

    或者如果你使用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'
    

    .

    设计使用the rails standard :notice rather than :success,但您可以将add the success (green) styling 用于您的css/scss(例如bootstrap_and_overriders.css.scss):

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

    【讨论】:

      猜你喜欢
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-24
      相关资源
      最近更新 更多