evhojq
Last Updated: September 09, 2019
·
878
· kostyadubinin

Ruby on Rails Flash messages with Foundation

There is a nice tip of how to do this with Bootstrap, https://coderwall.com/p/jzofog. But if you are using Foundation, here is how you can do the same with Foundation.

Add the following method to the ApplicationHelper:

def foundation_flash_class(level)
    case level.to_sym
    when :notice    then "alert-box"
    when :alert     then "alert-box warning"
    when :success   then "alert-box success"
    when :info      then "alert-box info"
    when :error     then "alert-box alert"
    when :secondary then "alert-box secondary"
    end
  end

and then add the following to the layout:

- flash.each do |key, value|
  .alert-box{class: foundation_flash_class(key)}(data-alert)
    = value
    %a.close{href:"#"} ×