Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I agree with apneadiving.. personally, the js.erb calls add alot of cognitive overhead. What I do is load my javvavscripts into a layout partial</p> <p>*app/views/layouts/_javascripts.html.haml</p> <pre><code>= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" = javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js' = javascript_include_tag "http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js" = include_javascripts :app = hoptoad_javascript_notifier = yield :javascripts </code></pre> <p>Then I use the <code>jammit</code> command from the <a href="http://documentcloud.github.com/jammit/" rel="nofollow">Jammit</a> gem to minifiy, and compress my js and css assets</p> <p><em>config/assets.yml</em></p> <pre><code>javascripts: app: - public/javascripts/rail.js - public/javascripts/underscore-min.js - public/javascripts/jquery.dump.js - public/javascrippts/etc*.js </code></pre> <p>The for each page needed custom page-level js, I throw a <code>content_for :javascripts</code> block in at the bottom of the page:</p> <p><em>app/views/something/awesome.html.haml</em></p> <pre><code>%h1 cool page Other cool stuff - content_for :javascripts do :javascript $(document).ready(function(){ console.log('This document is REaDY!! and, this page rocks'); $.ajax({ url: "#{new_item_path(@item)}", //ruby is evaluated due to string interpolation success: function(data) { console.log('Loaded ' + data + ' from ' + #{new_item_path(@item)}) } }); }; </code></pre> <p>This lets me then to a <code>render 'layouts/javascripts'</code> at the bottom of my <code>application.html.haml</code> layout, and all of my javascript geets piped to the bottom of the page, so speed up page load as <a href="http://developer.yahoo.com/performance/rules.html" rel="nofollow">suggested here by Yahoo</a> This also lets me use the erb to generate variables for the page-level js from Rails if needed</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