我试图直接访问此文件:http://example.com/assets/style.css
(位于/assets/stylesheets/style.css
)
它适用于开发,但我在生产中遇到404错误。
配置/初始化/ assets.rb:
Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile += %w( static_pages.css )
Rails.application.config.assets.precompile += %w( dashboard.css )
Rails.application.config.assets.precompile += %w( style.css )
配置/初始化/ production.rb:
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.force_ssl = false
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
答案 0 :(得分:1)
因为Rails Asset Pipeline预编译资产并添加fingerprint。您应该使用Asset Pipeline Helpers而不是硬编码http://example.com/assets/jquery-ui-slider-pips.css
。
如果您想使用没有Asset Pipeline的JS或CSS文件,只需将它们放到public
目录(或public
目录的任何子目录)并使用直接链接。即对于public/style1.css
文件,您可以使用网址http://example.com/style1.css