flash [:alert]不起作用,但是flash [:notice]在重定向时显示消息 [英] flash[:alert] not working, but flash[:notice] displays the message on redirect

查看:94
本文介绍了flash [:alert]不起作用,但是flash [:notice]在重定向时显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用rails_admin gem,配置如下

I am using rails_admin gem and the configuration is as follows

config.authorize_with do
  if current_user.nil? || current_user.role != 'admin'
    redirect_to main_app.root_path
    flash[:alert] = "Sorry you are not authorized!"
  end
end

当我使用 flash [ :notice] ,我可以在root_path上看到该消息,但是如果将其更改为 flash [:alert] ,则不会显示该消息想法为什么以及什么解决方案?

When I use flash[:notice], I can see the message on the root_path, but if I change it to flash[:alert] it does not display, any ideas why and what would be the solution?

我只想使用:alert ,因为更改了通知颜色

I want to use :alert only, since changing the notice color will result it displaying red font for all other notices.

推荐答案

您可能没有输出flash [:alert] ]散列到您的页面上。

It is likely that you're not outputting the flash[:alert] hash out onto your page.

在视图中查找将flash [:notice]输出到何处(可能在app / views / layouts / application.html.erb中(或类似内容),然后复制该行以发出提醒。

Look in your views for where you output flash[:notice] (probably in app/views/layouts/application.html.erb (or similar) and copy the line for your notice to alert. It should look something like this:

<% if flash[:alert] %>
      <div id="alert">
         <%= flash[:alert] %> 
      </div>
<% end %>

如果不存在类似的东西(或者您找不到),将其添加到您的视图(或布局)

If something like that doesn't exist (or you can't find it), add it to your view (or layout)

这篇关于flash [:alert]不起作用,但是flash [:notice]在重定向时显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆