Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are on the right track with wrapping in divs, but you can do it this way in the view:</p> <pre><code>&lt;%= f.error_message_on "name", :css_class =&gt; "inputError" %&gt; </code></pre> <p>There are probably many ways to do it. Having the controller return rjs is one way. To be unobtrusive, considered best practice, you would need to include a javascript file that fires the scriptaculous method when the page is loaded. I use the low pro library for unobtrusive javascript. Here is my suggestion:</p> <p>layout file:</p> <pre><code>&lt;%= javascript_include_tag :defaults, ‘lowpro’, 'form_behaviors.js' %&gt; </code></pre> <p>javascript_file_for_form_actions.js:</p> <pre><code>Event.addBehavior({ '.inputError' : function() { this.hide(); this.blindUp(); } }); </code></pre> <p>You could also conditionally load the javascript file using content_for and change your layout file.</p> <p>View file:</p> <pre><code>&lt;% content_for(:javascript) do %&gt; &lt;%= javascript_include_tag “form_behaviors” %&gt; &lt;% end %&gt; </code></pre> <p>Somewhere in Layout file:</p> <pre><code>&lt;% yield :javascript %&gt; </code></pre> <p>You can get a <a href="http://github.com/topfunky/unobtrusive" rel="nofollow noreferrer">unobtrusive plugin</a> that includes lowpro for you as well. For more information <a href="http://peepcode.com/products/unobtrusive-prototype-js" rel="nofollow noreferrer">Peepcode</a> has a good pdf about lowpro, as well as some good screencasts on javascript.</p>
 

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