3
votes

In my application I show messages to users like this way.

<% flash.each do |key, value| %>
    <div class="alert alert-<%= key %> alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <%= value %>
    </div>
<% end %>

I have following lines in my application

.alert-notice {
  @extend .alert-warning;
}

When I redirect user with redirect_to root_url, :notice => 'messages' everything perfect. Notice message can be seen. However when I direct user with redirect_to root_url, :info => 'messages', No message can be seen. I have debugged code and realised that flash is empty that condition.

It's ok:

redirect_to root_url, :notice => 'messages'

Here is problem:

redirect_to root_url, :info => 'messages'

Any suggestions ?

Thanks.

2

2 Answers

2
votes

If you want to use info you have to add this to application_helper.rb

add_flash_types :info

You can add as many extra types as you want, e.g.

add_flash_types :info, :success, :warning, :danger

Extra:

I would also suggest you get used to the new hast notation in Ruby

redirect_to root_url, info: 'messages' # instead of :info => ...
0
votes

:info is not a vaild option for redirect (only :alert and :notice can be used that way); so, to use info, you must assign it directly to flash.

Try this instead:

flash[:info] = 'messages'
redirect_to root_url

Or this:

redirect_to root_url, flash: { info: 'messages' }