Rails Devise I18n Flash Messages with Twitter Bootstrap

后端 未结 6 691
轻奢々
轻奢々 2020-12-23 23:47

Hello I am new to ruby on rails and I am struggling to understand I18n\'s flash messages. I am using devise, rails 4, and twitter bootstrap.I understand that devise only use

6条回答
  •  盖世英雄少女心
    2020-12-24 00:23

    The simplest solution I've found is to use a common partial for all flash messages while checking for :notice and :alertto replace with the necessary bootstrap class.

    So make /views/shared/_alerts.html.erb like this -

    <% flash.each do |message_type, message| %>
    
    <%= message %>
    <% end %>

    Add a helper method (I've added it to the application helper) like this -

    def flash_class_name(name)
        case name
        when "notice" then "success"
        when "alert"  then "danger"
        else name
        end
    end
    

    Include _alerts.html.erb in the application layout (or the parent layout for your application).

    That's it!

提交回复
热议问题