Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, you may create an <code>app/views/shared/_flash_messages.js.rjs</code> partial, which you can then render from anywhere (e.g. from other <code>rjs</code> partials.)</p> <p>My approach in these kinds of applications has been as follows:</p> <ul> <li><p>for non-AJAX responses that may have a flash:</p> <ul> <li>in the layout (e.g. <code>layouts/application.erb</code>), add e.g.:<br/><code>render :partial =&gt; 'shared/flash_messages.html.erb'</code></li> </ul></li> <li><p>for AJAX responses that may also need to display a flash message, I added the following <code>rjs</code> code:</p> <ul> <li>in each <code>rjs</code> response (e.g. <code>controller/action.js.rjs</code>), add e.g.:<br/><code>render :partial =&gt; 'shared/flash_messages.js.rjs'</code></li> </ul></li> </ul> <p>Where the two partials do the necessary to render the flash, then call <code>flash.discard(:error)</code> or <code>flash.discard(:notice)</code> as appropriate.</p> <p>Sample <code>app/views/shared/flash_messages.html.erb</code> file:</p> <pre><code>&lt;% if flash[:error] %&gt; &lt;div id="flash_message" class="error"&gt;&lt;%= h(flash[:error]) %&gt;&lt;/div&gt; &lt;% flash.discard(:error) %&gt; &lt;% elsif flash[:notice] %&gt; &lt;div id="flash_message" class="notice"&gt;&lt;%= h(flash[:notice]) %&gt;&lt;/div&gt; &lt;% flash.discard(:notice) %&gt; &lt;% else %&gt; &lt;div id="flash_message" style="display: none;" /&gt; &lt;% end %&gt; </code></pre> <p>Sample <code>app/views/shared/flash_messages.html.rjs</code> file:</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload