среда, 15 августа 2012 г.

Bootstrap и flash нотификации в Rails

В application_helper.rb:


  def twitterized_type(type)
    case type
      when :alert
        "alert-block"
      when :error
        "alert-error"
      when :notice
        "alert-info"
      when :success
        "alert-success"
      else
        type.to_s
    end
  end

В нужном месте лейаута или вьюхи:

=render :partial => "shared/flash_messages", :locals => {:flash => flash}
В паршеле _flash_messages.html.haml:

- flash.each do |type, message|
  %div.alert{ "data-alert" => "alert", :class => twitterized_type(type) }
    %a.close{:href => "#", "data-dismiss" => "alert"} ×
    %p
      = message


Комментариев нет:

Отправить комментарий