Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rails has had javascript helpers since early versions. </p> <p>The difference since Rails 3 is that now it's unobtrusive, by unobtrusive it means that functionality its separated from content.</p> <p>For example the following:</p> <pre><code>&lt;%= link_to "Delete", resource_path(@resource), :method =&gt; "delete", :confirm =&gt; "Are you sure?" %&gt; </code></pre> <p>Would render pre Rails 3</p> <pre><code>&lt;a href="/resource/1" onclick="//lots and lots of inline javascript code here"&gt;Delete&lt;/a&gt; </code></pre> <p>With Rails 3 UJS</p> <pre><code>&lt;a href="/resource/1" data-method="delete" data-confirm="Are you sure?"&gt;Delete&lt;/a&gt; </code></pre> <p>The difference is that unobtrusive javascript is handled without inline code in the views and passed through the "data" attributes and taken care of in the background with other default JS that is in your app that picks up this data attributes and runs the corresponding JS code.</p> <p>UJS is also commonly used for making remote (AJAX) calls using <code>:remote =&gt; "true"</code> or <code>link_to_remote</code>. </p> <p>More info on that here: <a href="http://guides.rubyonrails.org/ajax_on_rails.html" rel="nofollow">AJAX on Rails</a></p> <hr> <p>Basically UJS means that the javascript helpers included in Rails such as confirmation, and AJAX, among others are separated from the view code (HTML). </p> <p>UJS helpers can also be easily switched out for example if you prefer to use Prototype you could switch easily from jQuery while keeping the helpers functionality.</p> <p>Why Rails older versions didn't support UJS, is because it just wasn't built in at the time, so it was done with inline JS.</p>
    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. 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