Cninroh
Cninroh

Reputation: 1796

How to not merge all js into one file in Rails 3.2?

I use Rails 3.2. I am using a lot of JS gems, and most of them require to be called in specific order. In development it automatically seperates different JS files like this :

<link href="/assets/companies.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/contacts.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/fake_json.css?body=1" media="all" rel="stylesheet" type="text/css" />

But in production it merges all of the files like this :

<script src="/assets/application-e30cf15d1afc4b59752074fa16cd83a3.js" type="text/javascript"></script>

In my specific case, I do not want or require Rails to do this for me. I tried to cancel this by using config.assets.compress = false and config.assets.debug = true in production.rb file, but it has no effect even after restarting the server.

How do I enable "not merging" on production?

Upvotes: 1

Views: 1530

Answers (3)

avjaarsveld
avjaarsveld

Reputation: 599

Do you perhaps have a javascript_include_tag :application, :defer => true, :debug => false in a view?

Your questions helped me with a similar issue (+1). I needed to set config.assets.debug = true in development.rb and <%= javascript_include_tag :application, :defer => true, :debug => true %> in shared/_settings.html.erb

Upvotes: 0

bgates
bgates

Reputation: 2373

If the reason you don't want them all merged is that they need to be loaded in a specific order, and the default is compiling them alphabetically, you can get rid of the

require_tree

line in application.js and write out separate require statements in the order in which you need them.

Upvotes: 1

Baldrick
Baldrick

Reputation: 24340

You can add the following line to the production.rb

config.assets.compile = false

Check the Configuring Rails guide for other useful parameters.

Upvotes: 0

Related Questions