我正在尝试在我拥有的旧 Rails 应用程序上设置资产管道,以便我可以开始使用 CoffeeScript。我正在使用 ruby 1.9.3-p327 和 Rails 3.2.13。我曾经把我所有的 JS、CSS 和我的图片都存放在public/
文件夹中。这就是我到目前为止所做的->
我将它们全部移至应用程序/资产,我为 JS 和 CSS 调用添加了清单文件
//= require_tree .
。添加了以下宝石
group :assets do gem 'coffee-rails' gem 'uglifier' gem 'sass-rails' gem 'therubyracer' end
删除了我的所有
javascript_include_tags
除了= javascript_include_tag 'https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'
将以下内容添加到我的
config/application.rb
文件中# Enforce whitelist mode for mass assignment. # This will create an empty whitelist of attributes available for mass-assignment for all models # in your app. As such, your models will need to explicitly whitelist or blacklist accessible # parameters by using an attr_accessible or attr_protected declaration. config.active_record.whitelist_attributes = true # Enable the asset pipeline config.assets.enabled = true # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0'
在 config/environments/development.rb 文件集中
# Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true
我添加到 config/environments/production.rb
# Compress JavaScripts and CSS config.assets.compress = true # Choose the compressors to use # config.assets.js_compressor = :uglifier # config.assets.css_compressor = :yui # 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 # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) # config.assets.precompile += %w( search.js )
我重新阅读了资产管道上的部分,只是为了看看我是否搞砸了。但到目前为止,没有任何资产从app/assets
唯一有效的资产中拉出来jquery.min.js
,include_tag
我已经尝试移除它并再次尝试不掷骰子。
我试过bundle exec rake assets:clean
, 和bundle exec rake assets:precompile
, 两者都运行没有问题。并在为资产添加 gem 后捆绑,并且每次都重新启动 pow。
我不确定我是否正在经历这一切都错了,或者我错过了一步?任何人以前经历过这个和提示或线索将不胜感激。