How do I include page-specific JavaScript?
ruby, ruby-on-rails-3
Solution
I use `content_for`.
application.html.erb
<head>
<%= yield :custom_js %>
</head>
your_page.html.erb
<% content_for :custom_js do %>
<!-- your script includes go here -->
<% end %>
Problem
In my Rails app, every page includes all of the JavaScripts in `assets`. Some custom scripts are for Ajax and some fancy stuff. which run unnecessarily from every page and are causing me unnecessary overload. For example, the session page doesn't really need any JavaScript at all, still all scripts are included. How do I change this? I have Rails 3.2.2. ``` <script src="/assets/jquery-1.7.2.js?body=1" type="text/javascript"></script> <script src="/assets/jquery.ui.core.js?body=1" type="text/javascript"></script> <script src="/assets/jquery.ui.widget.js?body=1" type="text/javascript"></script> <script src="/assets/jquery.ui.position.js?body=1" type="text/javascript"></script> <script src="/assets/jquery.ui.autocomplete.js?body=1" type="text/javascript"></script> <script src="/assets/special.js?body=1" type="text/javascript"></script> ```