1

I have a javascript in the vendors/assets/javascripts folder, and I have this line of code:

<script src="assets/grid.js"></script>

in one of my app/views page.

This grid.js file (inside the vendors directory) works when I test it out in localhost, but when I precompile and push my application to heroku, it says:

GET http://www.domain.com/assets/grid.js 404 (Not Found)

Why is this occurring?

Thanks

hellomello
  • 8,219
  • 39
  • 151
  • 297

2 Answers2

3

I would use the javascript_include_tag instead and that should work

<%= javascript_include_tag("grid.js") %>

In production I believe that the asset pipeline adds a hash onto the name of grid.js for fingerprinting (Section 1.2 of that documentation) so you can't use that path <script src="assets/grid.js"></script>

strivedi183
  • 4,749
  • 2
  • 31
  • 38
  • I'm still getting an error, but this time it says that : `ActionView::Template::Error (grid.js isn't precompiled)` which is weird because I did `rake assets:precompile` and also `heroku run rake assets:precompile` – hellomello Nov 26 '13 at 07:27
  • Try putting `config.assets.precompile += ['grid.js']` in your `config/application.rb` file – strivedi183 Nov 26 '13 at 07:43
  • hmm i tried this at first, but it didn't work. so then I added this and changed `config.assets.compress = false` to `true`. Does this sound the right thing to do as well? – hellomello Nov 26 '13 at 07:56
  • Are you using Rails 3? Try `config.assets.initialize_on_precompile = false` in your `config/application.rb`, more on that in the [heroku documentation](https://devcenter.heroku.com/articles/rails-asset-pipeline#the-rails-3-asset-pipeline) – strivedi183 Nov 26 '13 at 08:07
  • Yeah, I'm using rails 3. I do have it set on false also. Setting my `config.assets.compress = true` made it work. Was this not the correct solution to do so? – hellomello Nov 26 '13 at 08:19
  • Check out this [SO thread](http://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not), it says it slows down the site, honestly, I'm not sure why your previous attempts were not working – strivedi183 Nov 26 '13 at 08:27
  • I'm not sure either, but thanks for your help. I'll accept this answer – hellomello Nov 26 '13 at 14:51
0

I tried: Set config.assets.compress = true in my config/environments/production.rb and all was fine, but it is a bad practice and gain bad performance. Yo can see this for more details config.assets.compile=true in Rails production, why not?

My solution: Run in your local project RAILS_ENV=production bundle exec rake assets:precompile and push all the files generated in public/assent/ in your github repo and deploy in heruko. Yo can read this for more details https://devcenter.heroku.com/articles/rails-asset-pipeline#compiling-assets-locally

Community
  • 1
  • 1
gorums
  • 1,567
  • 13
  • 5