lkartono
lkartono

Reputation: 2393

Rails precompile multiple javascript_includes_tag

I'm actually building a new app under Rails 4. I used to put my javascript_includes_tag at the bottom of my layout. But for an unknown reason, it creates a bug when trying to use confirm: on delete link. So I put back this line at the top :

!!!
%html{ :lang => 'en' }
  %head
    = stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
    = javascript_include_tag "application", "data-turbolinks-track" => true

So far so good, the bug is now gone. Anyway, since my app is gonna use a lot of Javascript, I still need to load those third part library at the bottom. So, what I did is to only let the Rails library at the top :

// application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks

Then I tried to create another js file named third-part and try to do the same as application but including my third part libraries. Unfortunately, it does not work.

// third-part.js
//= require bootstrap
//= require app
//= require app.plugin

How can I add another javascript_includes_tag at the bottom the same way I did for application? Here I mean that on production it will also compress those files.

Thanks a lot for your help

EDIT :
It's actually loading my files well on DEVELOPMENT, but not on my production.
On production I just got <script data-turbolinks-track="true" src="/javascripts/third-part.js"></script> and I can't access the file

I've tried :

config.assets.precompile += %w( third-part.js )

and

rake assets:precompile RAILS_ENV=production

but it still not working

EDIT 2 :
I made a test of precompliling on production mode from my local machine. It did work. It might be a problem with my server.

EDIT 3 :
Just earse my application from server and clone a new one from my Github but it's still not working. Don't know why :(

Upvotes: 0

Views: 67

Answers (1)

techvineet
techvineet

Reputation: 5111

In your config/environments/production.rb add this line to precompile the external assets

config.assets.precompile += ["third-part.js"]

and don't forget to mention env=production while precompiling assets on production.

Upvotes: 1

Related Questions