Rails flash message
RAILS FLASH BOOTSTRAP
Ruby on Rails Flash messages with Bootstrap
If you're using Ruby on Rails and Bootstrap originally from Twitter, then you may want to display flash messages with the alert styles. Here is a quick and easy way of doing so.
You just need to quickly extend application_helper.rb with the following:
def flash_class(level)
    case level
        when :notice then "alert alert-info"
        when :success then "alert alert-success"
        when :error then "alert alert-error"
        when :alert then "alert alert-error"
    end
end
Now when you call a flash message, you can use the following in your view:
<% flash.each do |key, value| %>
      <div class="<%= flash_class(key) %>">
            <%= value %>
      </div>
<% end %>
And just use:
flash[:success] = "Woohoo!"
As a success or:
flash[:alert] = "Alerting you to the monkey on your car!"
阅读量: 808
发布于:
修改于:
发布于:
修改于: