플래시 메시지를 표시하고 Ajax로 렌더링하려하지만 페이지를 새로 고침 할 때까지 메시지가 으로 표시되지 않는 것 같습니다. 여기에 내 응용 프로그램 레이아웃 뷰의 관련 부분레일상의 루비에서 Ajax 플래시 메시지
page.insert_html :top, :feed_items, :partial => 'shared/feed_item', :object => @micropost
page.replace_html :user_info, pluralize(current_user.microposts.count, "micropost")
page[:micropost_form].reset
page.replace_html :notice, flash[:notice]
flash.discard
:
<div id= "notice"><% flash.each do |key, value| %>
<div class="flash <%= key %>"><%= value %></div>
<% end %></div>
그리고 여기 내 micropost 컨트롤러의 관련 부분 :
class MicropostsController < ApplicationController
before_filter :authenticate, :only => [:create, :destroy]
before_filter :authorized_user, :only => :destroy
def create
@micropost = current_user.microposts.build(params[:micropost])
respond_to do |format|
if @micropost.save
flash[:success] = "Micropost created!"
format.html { redirect_to root_path }
format.js
else
@feed_items = []
render 'pages/home'
end
end
end
여기 내 create.rjs 파일입니다
플래시 메시지가 표시되지 않는 이유는 무엇입니까?
룩을 시도해보십시오 http://stackoverflow.com/questions/366311/how-do-you-handle-rails-flash- with-ajax-requests – Peyman
정확히 원하는대로 할 수 있을지 모르지만 flash.now [: success] –