javascript_include_tag: default values ​​do not work


I'm migrating an app to Rails 3. The following - which I've seen recommended in a few places - does not work:

<%= javascript_include_tag :defaults %>

In my case, it expands to this:

<script src="/assets/defaults.js" type="text/javascript"></script>

... which results in a 404. As I understand it, the :defaults is not supposed to include a file called "defaults.js"; it's supposed to include a few essential things like prototype.js and application.js.

Note that in my case, the following works fine. It's just that I'd rather use the official recommended way, if possible:

<%= javascript_include_tag :prototype %>
<%= javascript_include_tag :application %>

I'm running Rails 3.2.8 with ruby 1.9.3.

I do not have the following line in my config/application.rb (in any form). To migrate to Rails 3, I created a new Rails 3 application, and used that application.rb as a starting point:

config.action_view.javascript_expansions[:defaults] = %w(foo.js bar.js)

In app/assets/javascripts, I have:


... and a bunch of stuff specific to my application.

Since Rails 3.1, it uses assets pipeline. It means you need to change your management of assets.

You have a assets/javascripts/application.rb file which contains something like this:

//= require jquery
//= require jquery_ujs
//= require_tree .

It seems you include jquery, jquery_ujs and all other files in the javascripts repository. With the last line you don't need to do anything else in this file. You just need to include the application file in your view and rails will manage everything:

<%= javascript_include_tag "application" %>

It's exactly the same thing with stylesheets.

Then in production environment, assets (images, stylesheets, javascripts) will be compiled and minified in order to be more efficient.

I suggest you read more about here

Hope this helps