はい、あなたはその後、どこからでもレンダリングすることができ、app/views/shared/_flash_messages.js.rjs
部分を作成すること(例えば、他のrjs
パーシャルから。)
次のようにこの種のアプリケーションでの私のアプローチがされています:
01:フラッシュを有することができる非AJAX応答のための
2つの部分がフラッシュをレンダリングするのに必要な場合は、flash.discard(:error)
またはflash.discard(:notice)
を適切に呼び出します。
サンプルapp/views/shared/flash_messages.html.erb
ファイル:
<% if flash[:error] %>
<div id="flash_message" class="error"><%= h(flash[:error]) %></div>
<% flash.discard(:error) %>
<% elsif flash[:notice] %>
<div id="flash_message" class="notice"><%= h(flash[:notice]) %></div>
<% flash.discard(:notice) %>
<% else %>
<div id="flash_message" style="display: none;" />
<% end %>
サンプルapp/views/shared/flash_messages.html.rjs
ファイル:
if !flash[:error].blank?
page['flash_message'].
replace_html(flash[:error]).
removeClassName('notice').
addClassName('error').
show()
else
page['flash_message'].
replace_html(flash[:notice]).
removeClassName('error').
addClassName('notice').
show()
end
ありがとう。これはまさに私が望んでいた例のようなものでした。私のjs.erbファイルは今よりはるかにクリーンです;) – atmorell