H D
H D

Reputation: 554

flash[:alert] not working, but flash[:notice] displays the message on redirect

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.

Upvotes: 2

Views: 4578

Answers (1)

Yule
Yule

Reputation: 9754

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)

Upvotes: 4

Related Questions