图像和资产在rails 3.1.0上的生产服务器中不起作用

时间:2022-05-04 00:26:35

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

我将服务器切换到生产状态,无法加载任何图像。这一切都在开发模式下工作正常但是当我切换到生产时它都停止工作我已经启用了server_static_assets但仍然没有任何效果。这样做的任何帮助

3 个解决方案

#1


25  

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.

1 - 您的生产配置可能不正确。如果您从早期的3.1版本候选版本开始,并且一直在更新,则特别有可能。生产的建议选项.rb在rc4和3.1.0版本之间发生了很大的变化。

Make sure that your production.rb settings include:

确保您的production.rb设置包括:

# 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

2 - 您可能忘记了预编译资产

RAILS_ENV=production rake assets:precompile

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

3 - 您可能忘记重新启动Web服务器以获取production.rb中的更改。

#2


1  

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

请记住运行rake资产:在生产环境中预编译。

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

如果您需要使用Capistrano进行部署,可以使用以下配方:

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


1  

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

如果您要升级到Rails 4或正在生产中使用它,并且正在从css加载图像,那么:

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

请参阅http://guides.rubyonrails.org/asset_pipeline.html#css-and-sass以供参考

#1


25  

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.

1 - 您的生产配置可能不正确。如果您从早期的3.1版本候选版本开始,并且一直在更新,则特别有可能。生产的建议选项.rb在rc4和3.1.0版本之间发生了很大的变化。

Make sure that your production.rb settings include:

确保您的production.rb设置包括:

# 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

2 - 您可能忘记了预编译资产

RAILS_ENV=production rake assets:precompile

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

3 - 您可能忘记重新启动Web服务器以获取production.rb中的更改。

#2


1  

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

请记住运行rake资产:在生产环境中预编译。

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

如果您需要使用Capistrano进行部署,可以使用以下配方:

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


1  

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

如果您要升级到Rails 4或正在生产中使用它,并且正在从css加载图像,那么:

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

请参阅http://guides.rubyonrails.org/asset_pipeline.html#css-and-sass以供参考