Jak rozwiązujecie problem wiadomości flash i ajaxowych requestów?
W tej chwili mam coś takiego:
$("div#flash_messages").html("<%= escape_javascript flash_messages %>");
setTimeout(function() { $('div#flash_messages div').fadeOut('fast') }, 2000);
<% flash.discard %>
Niby działa jak należy, ale nie widzi mi się wrzucać to do każdego js-owego widoku. Próbowałem wrzucić do do app/assets ale rzuca się o brak helperów (#flash_messages konkretnie).
#flash_messages to helper, który renderuje partiale, tak żeby div-y były zgodne z Twitter-owym Bootstrap-em:
[code=ruby]def flash_messages
div = lambda {|name, msg| render partial: ‘flash_messages’, locals: {name: name, msg: msg} }
[flash.map {|name, msg| div[name, msg]}].join.html_safe
end
_flash_messages.html.haml
%div{class: [‘alert-message’, bootstraped_flash_type(name), :fade, :in], “data-alert” => :alert, id: “flash_#{name}”}
%a.close{:href => “#”} ×
%p= msg[/code]
i fragment layoutu:
[code=html]