Rails 3.1生产中的资产管道 [英] Rails 3.1 assets pipeline in production
问题描述
我正在使用资产管道(在Rails 3.1.3中),并且正在努力使其在生产中工作.
I am using the assets pipeline (in Rails 3.1.3) and am kind of struggling to make it work in production.
在我的/app/assets/stylesheets
目录中,有以下文件:
In my /app/assets/stylesheets
directory I have the following files:
application.css --> this is the default rails one
stylesheet.css --> This is my custom stylesheet
我花了很多时间将我的stylesheet.css
包含在生产环境中的/public/assets/
目录中(通过运行rake assets:precompile
),最终我通过将以下行添加到我的application.rb
文件中来做到了: >
I spent a lot of time getting my stylesheet.css
included in the /public/assets/
directory in production (by running rake assets:precompile
) and I finally made it by adding the following line into in my application.rb
file:
config.assets.precompile += ['stylesheet.css']
我知道生产中的预编译stylesheet.css
文件正确.
I know have the right precompiled stylesheet.css
file in production.
我的问题是在stylesheet.css
文件中使用stylesheet_link_tag
时.事实证明:
The problem I have is when using stylesheet_link_tag
with my stylesheet.css
file. It turns out:
<%= stylesheet_link_tag "stylesheet" %>
在生产中将解析为<link href="/stylesheets/stylesheet.css" media="screen" rel="stylesheet" type="text/css">
,我希望将路径解析为/assets/stylesheet.css
,就像在开发中一样.
<%= stylesheet_link_tag "stylesheet" %>
is resolved into <link href="/stylesheets/stylesheet.css" media="screen" rel="stylesheet" type="text/css">
in production I would expect the path to be resolved into /assets/stylesheet.css
just like it does in development.
更令人惊讶的是,即使<%= stylesheet_link_tag "application"%>
解析为<link href="/stylesheets/stylesheet.css" media="screen" rel="stylesheet" type="text/css">
,application.css
的表现也很完美.我不明白的是,rails 3.1中不存在public/stylesheets/目录.
What is even more surprising is that application.css
behaves perfectly even though <%= stylesheet_link_tag "application"%>
resolves into <link href="/stylesheets/stylesheet.css" media="screen" rel="stylesheet" type="text/css">
. What I don't understand is that the public/stylesheets/ directory does not exist in rails 3.1.
有什么主意吗?
推荐答案
Richard Hulse的答案将我引向了正确的方向.发生的事情真的很微妙.
Richard Hulse answers pointed me to the right direction. What happens is really subtle..
我的问题的答案是> Rails 3.1资产没有生产中的指纹.
基本上,我的项目使用mongoid而不是ActiveRecord.根据Mongoid关于配置的文档,可以将application.rb
文件修改为不包含ActiveRecord
表示删除:
Basically, my project use mongoid instead of ActiveRecord. According to Mongoid documentation about configuration, the application.rb
file can be modified to not include ActiveRecord
which means removing:
require railties/all
并替换为:
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
# require "sprockets/railtie" # Uncomment this line for Rails 3.1+
我曾经很习惯用Rails 3.0.x进行这种操作,以至于我没有注意与Rails 3.1相关的评论
I was so used to doing this manipulation with rails 3.0.x that I did not pay attention to the comment related to Rails 3.1
我的问题是我不需要链轮!
谢谢大家的帮助!
这篇关于Rails 3.1生产中的资产管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!