ROR学习笔记(40)——如何在ajax下flash[:notice]

http://stackoverflow.com/questions/366311/how-do-you-handle-rails-flash-with-ajax-requests
参考上面的文章就行了。。我只看懂了下面的一种,能够实现。。。。:
controller

respond_to do |format|
    flash.now[:notice] = @msg / 'blah blah...'
    format.html 
    format.js
  end

view

<%= render :partial => 'layouts/flash' , :locals => { :flash => flash } %>

layouts/_flash.html.erb

<% flash.each do |name, msg| %>
            
x

<%= msg %>

<% end %>

post.js.erb

$("#notice").html("<%= escape_javascript(render :partial => 'layouts/flash' , :locals => { :flash => flash }).html_safe %>");

你可能感兴趣的:(ROR学习笔记(40)——如何在ajax下flash[:notice])