[英]Rails - Loading assets through the Asset Pipeline
I am trying to set up asset pipeline on a older rails app that i have so that i can start using CoffeeScript. 我正在尝试在较旧的Rails应用程序上设置资产管道,以便可以开始使用CoffeeScript。 i am using ruby 1.9.3-p327 and Rails 3.2.13.
我正在使用ruby 1.9.3-p327和Rails 3.2.13。 I used to stash all my JS, CSS and my images in the
public/
folder. 我曾经将所有JS,CSS和图像保存在
public/
文件夹中。 This is what i have done so far -> 这是我到目前为止所做的->
I moved them all to app/assets, i added the manifest files for both JS and CSS call //= require_tree .
我将它们全部移至app / assets,为JS和CSS调用
//= require_tree .
添加了清单文件//= require_tree .
. 。
Added the following gems 添加了以下宝石
group :assets do gem 'coffee-rails' gem 'uglifier' gem 'sass-rails' gem 'therubyracer' end
Removed all my javascript_include_tags
except for = javascript_include_tag 'https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'
删除了除
= javascript_include_tag 'https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'
以外的所有我的javascript_include_tags
Added the following to my config/application.rb
file 将以下内容添加到我的
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'
Within the config/environments/development.rb file set 在config / environments / development.rb文件集内
# Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true
I added to the config/environments/production.rb 我添加到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 )
I re-read the section on the Asset Pipeline just to see if i messed up anything. 我重新阅读了资产管道中的部分,以查看是否弄乱了任何内容。 But so far none of the assets are pulling through from
app/assets
the only one that is working is the jquery.min.js
that i have coming in through include_tag
i have tried removing it and trying again no dice. 但是到目前为止,所有资产都没有从
app/assets
资产中撤出,唯一起作用的是我通过include_tag
进入的jquery.min.js
,我尝试将其删除,然后再尝试一次没有骰子。
I have tried bundle exec rake assets:clean
, and bundle exec rake assets:precompile
, both of which run without issues. 我已经试过
bundle exec rake assets:clean
和bundle exec rake assets:precompile
,它们都没有问题。 and have bundled since adding the gems for the assets, and restarted pow each time. 自从为资产添加宝石以来就捆绑了,并且每次都重新启动战俘。
I am not sure if i am going through this all wrong or i have missed a step? 我不确定我是否经历了所有错误或错过了一步? any one gone through this before and tips or clues would be much appreciated.
任何在此之前经历过的人,都将不胜感激提示或线索。
You said you removed all the javascript_include_tag
statements. 您说您删除了所有
javascript_include_tag
语句。 Assuming you named the manifests app/assets/javascripts/application.js
and app/assets/stylesheets/application.css
, you'll need to include those in your layout: 假设您将清单清单命名为
app/assets/javascripts/application.js
和app/assets/stylesheets/application.css
,则需要在布局中包括这些清单:
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
Otherwise, Rails won't know to load your manifest files 否则,Rails将不知道加载清单文件
Also, you shouldn't be using rake assets:precompile
in development. 另外,您不应该在开发中使用
rake assets:precompile
。 If you do, then anytime you change a JS/CSS file, you'll have to recompile the assets before your changes show up. 如果这样做,那么无论何时更改JS / CSS文件,都必须在出现更改之前重新编译资产。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.