问题
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
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?
I want to use :alert
only, since changing the notice color will result it displaying red font for all other notices.
回答1:
It is likely that you're not outputting the flash[:alert] hash out onto your page.
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)
来源:https://stackoverflow.com/questions/32690339/flashalert-not-working-but-flashnotice-displays-the-message-on-redirect