生产中的 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";%>
被解析为 在生产中我希望路径被解析为
/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";媒体=屏幕"rel=样式表"type="text/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 documentation 关于配置,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屋!