问题描述
我花了整整一天的时间来弄清楚这个问题,但没有任何积极的结果.当我加载网站时,没有CSS,图像或有效的javascript.
I've spent the whole day trying to figure out this issue, but without any positive results.When I load my website, there are no CSS, images or working javascript.
该应用程序在Rails 3.2.13
和Capistrano 2上运行.
The app is running on Rails 3.2.13
and Capistrano 2.
这是我的设置:
config/environments/production.rb
Appname::Application.configure do
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
#config.serve_static_assets = false
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.precompile = ['*.js', 'application.css', 'styles.css.scss', '*.css.erb']
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg *.woff *.ttf *.ico)
config.assets.digest = true
config.cache_store = :memory_store
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module Apname
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password]
config.active_support.escape_html_entities_in_json = true
config.active_record.whitelist_attributes = true
config.assets.enabled = true
config.assets.paths << "#{Rails.root}/app/assets/fonts"
config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/
config.assets.version = '1.0'
config.assets.initialize_on_precompile = false
end
end
我在本地运行bundle exec rake assets:precompile
->这些文件已生成到public/assets
目录.
I ran locally bundle exec rake assets:precompile
-> the files were generated to the public/assets
directory.
但仍然-生产中没有资产.
But still -- there are no assets on production.
我还不知道要在配置文件中进行哪些更改,在生产服务器上仍然是相同的结果.
I have already no idea what to change in the config files, still the same result on the production server.
我们将竭诚感谢您的帮助!
Every help will be warmly appreciated!
我刚刚在控制台中注意到,图像已正确加载(我可以加载http://website.com/assets/social_icons/facebook_ico.png
),但CSS + JS却不正确(http://IP/assets/application-3b6ba7703e465259e4e7ebee17c5ea1e.js
404未找到-与.css相同)
I just noticed in the console that images are loaded correctly (I can load http://website.com/assets/social_icons/facebook_ico.png
), but not CSS+JS (http://IP/assets/application-3b6ba7703e465259e4e7ebee17c5ea1e.js
404 NOT FOUND - the same for .css)
推荐答案
您是否在编译资产后尝试重新启动Web服务器?
Did you try to restart the webserver after compiling the assets?
权限设置是否正确(chmod 755 . -R
)?
Are the rights set correctly (chmod 755 . -R
)?
还要检查您的网络服务器配置是否指向 app_root/public 而不是 app_root
Also, check that your webserver configuration points to app_root/public and not just app_root
检查是否可以直接加载URL.此外,请验证呈现的页面是否显示正确缓存的URL.
Check if you can load the url directly. In addition verify that the rendered page display correctly-cached urls.
如果两者之一失败,请尝试针对生产环境强制进行编译
If one of the two fails try forcing compilation for production environment
rake assets:precompile RAILS_ENV=production
如果没有任何效果,请尝试回滚到用于生产的默认资产配置:
If nothing works try rolling back to default assets config for production:
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
代替:
#config.serve_static_assets = false
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.precompile = ['*.js', 'application.css', 'styles.css.scss', '*.css.erb']
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg *.woff *.ttf *.ico)
config.assets.digest = true
我刚刚在控制台中注意到图像已正确加载(我可以 加载 http://website.com/assets/social_icons/facebook_ico.png ),但是不是 CSS + JS (http://****/assets/application-3b6ba7703e465259e4e7ebee17c5ea1e.js 404 未找到-与.css相同
I just noticed in the console that images are loaded correctly (I can load http://website.com/assets/social_icons/facebook_ico.png), but not CSS+JS (http://****/assets/application-3b6ba7703e465259e4e7ebee17c5ea1e.js 404 NOT FOUND - the same for .css)
这也意味着您实际上并没有在编译资产.如果是的话,则需要使用名称后面的哈希值加载facebook_ico.png
That also means you aren't actually compiling assets. If you were, you'd need to load facebook_ico.png with the hash attached to the name
这篇关于Rails 3.2.13-资产未在生产中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!