Created
January 9, 2011 19:31
-
-
Save lucassimao/771932 to your computer and use it in GitHub Desktop.
Best way to add page specific javascript in a Rails 3 app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What I like to do is include the per-view Javascript in a content_for :head block and then yield to that block in your application layout. For example | |
If it's pretty short then: | |
<% content_for :head do %> | |
<script type="text/javascript"> | |
$(function() { | |
$('user_rating_positve').click(function() { | |
$('some_div).show(); | |
} | |
}); | |
</script> | |
<% end %> | |
or, if longer, then: | |
<% content_for :head do %> | |
<script type="text/javascript"> | |
<%= render :partial => "my_view_javascript" | |
</script> | |
<% end %> | |
Then, in your layout file | |
<head> | |
... | |
<%= yield :head %> | |
</head> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment