Images and assets not working in my production server on rails 3.1.0

我是研究僧i 提交于 2019-12-17 23:08:56

问题


I switched my server to production and i cannot get any of my images to load. It all works fine on development mode but when i switched to production it all stopped working i have enabled server_static_assets and still yet nothing works. Any help towards doing this


回答1:


Here are a few problems that you might be having:

1 - Your production configuration may not be correct. This is particularly likely if you started out with an early 3.1 release candidate, and have been updating along the way. The suggested options for production.rb changed quite a bit between rc4 and the 3.1.0 release.

Make sure that your production.rb settings include:

# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true

2 - You may have forgotten to precompile your assets

RAILS_ENV=production rake assets:precompile

3 - You may have forgotten to restart your web server to pick up the changes in production.rb.




回答2:


Remember to run rake assets:precompile in your production environment.

If you need are deploying with Capistrano, you can use this recipe:

before "deploy:symlink", "assets:precompile"

namespace :assets do
  desc "Compile assets"
  task :precompile, :roles => :app do
    run "cd #{release_path} && rake RAILS_ENV=#{rails_env} assets:precompile"
  end
end



回答3:


If you are upgrading to Rails 4 or are currently using it on production, and are loading images from css, then:

instead of

background-image: url('some_image.jpg');

do

background-image: image-url('some_image.jpg');

See http://guides.rubyonrails.org/asset_pipeline.html#css-and-sass for reference



来源:https://stackoverflow.com/questions/7340635/images-and-assets-not-working-in-my-production-server-on-rails-3-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!