hellomello
hellomello

Reputation: 8597

Rails: Heroku assets in vendor getting 404

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

Upvotes: 1

Views: 618

Answers (2)

gorums
gorums

Reputation: 1737

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

Upvotes: 0

strivedi183
strivedi183

Reputation: 4831

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>

Upvotes: 3

Related Questions