You have to run this first. I've had this issue myself before.
rake assets:precompile RAILS_ENV=production
and then reload the server.
質問
In production the generated html for the image_tag helper returns a 404 error. Asset pipeline is enabled
In the haml file
=image_tag "how_it_works_1.jpg"
how_it_works_1.jpg file is located at app/assets/images/how_it_works_1.jpg
When I deploy in production with mina I can find this asset under current/public/assets/how_it_works_1-5e40b2326fc14e879ae476a3fd6aef97.jpg
however the generated html doesn't point to this asset but to /images/how_it_works_1.jpg which returns a 404
<img src="/images/how_it_works_1.jpg"/>
it's working under the development env
<img src="/assets/how_it_works_1.jpg"/>
edit: I am using apache2.4 together with passenger here is an extract of my production.rb:
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = true
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.digest = true
config.assets.version = '1.0'
解決
You have to run this first. I've had this issue myself before.
rake assets:precompile RAILS_ENV=production
and then reload the server.
他のヒント
It seems like your assets are precompiling successfully. However, Rails defaults to refusing to serve static assets in production. This Rails guide has a bit more information. (Ctrl-F for config.serve_static_assets
)
To answer your question, you will need to configure your web server (is it Apache, nginx, or something else?) to serve the static assets from your deploy's public/assets/
directory.
If you edit your question to include your web server, I can give you a link to more specific instructions. Cheers!
It seems like config.assets.digest
is not true in config/environments/production.rb (by default it should be true).