代码之家  ›  专栏  ›  技术社区  ›  Vu Levitan

Ruby on Rails 4 Device何时调用require_no_authentication方法?

  •  3
  • Vu Levitan  · 技术社区  · 9 年前

    我在使用device时遇到消息问题:

    1.我不想在登录并重定向到管理员首页后显示警报

    2.我重写方法require_no_authentication of device

      def require_no_authentication
        super
        flash.delete :alert
      end
    

    4.我有如下解决方案:

      def require_no_authentication
        super
        flash.delete :alert unless flash[:alert] ==
          I18n.t("devise.failure.admin.inactive")
      end
    

    我无法涵盖所有登录注销时发出闪烁警报的情况

    5.我们可以有另一个实现吗,你能告诉我所有的情况都会调用require_no_authentication方法吗? 非常感谢!

    1 回复  |  直到 9 年前
        1
  •  0
  •   Muaaz Rafi    9 年前

    sessions:
      signed_in: ''
    

    在渲染警报的地方进行检查。

    <% flash.each do |name, msg| %>
      <%= content_tag :div, msg, :id => "flash" if msg.length > 0 %>
    <% end %>
    

    您可以使用css,但不能使用perfered。

    .flash.alert:empty {
      display: none;
    }
    

    对于require_no_authentication方法,它是device内部使用的一个预操作。不建议重写此方法。如果您对此解决方案有任何问题,请告诉我。