我正在尝试在我拥有的旧版rails应用程序上设置资产管道,以便我可以开始使用CoffeeScript。我正在使用ruby 1.9.3-p327和Rails 3.2.13。我曾经把我的所有JS,CSS和我的图像藏在public/
文件夹中。这就是我到目前为止所做的事情 - >
我将它们全部移动到app / assets,我添加了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 )
我重新阅读Asset Pipeline上的部分只是为了看看我是否搞砸了什么。但到目前为止,没有任何资产从app/assets
开始,唯一正在运作的是jquery.min.js
我通过include_tag
进入我尝试删除它并再次尝试没有骰子
我尝试了bundle exec rake assets:clean
和bundle exec rake assets:precompile
,两者都没有问题。自从为资产添加宝石后捆绑了,每次都重启pow。
我不确定我是否经历过这一切,或者我错过了一步?任何人经历过此之前和提示或线索将非常感激。
答案 0 :(得分:4)
你说你删除了所有javascript_include_tag
语句。假设您将清单命名为app/assets/javascripts/application.js
和app/assets/stylesheets/application.css
,则需要在布局中包含这些清单:
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
否则,Rails不知道加载您的清单文件
此外,您不应该在开发中使用rake assets:precompile
。如果这样做,那么无论何时更改JS / CSS文件,您都必须在更改显示之前重新编译资产。