具有Suburis的Rails 3.1资产管道 [英] Rails 3.1 asset pipeline with suburis
问题描述
我正在尝试转换Rails 3.1应用程序以使用资产管道.当前使用Rails 3.2.0.rc2.我将ENV['RAILS_RELATIVE_URL_ROOT']
设置为application.rb中的suburi.辅助程序工作正常,可以生成文件的正确路径(包括suburi),但是Rails路线并不能从该路径提供文件.
I'm trying to convert a Rails 3.1 app to use the asset pipeline. Currently using Rails 3.2.0.rc2. I'm setting ENV['RAILS_RELATIVE_URL_ROOT']
to the suburi in application.rb. The helpers work fine, generating the correct path (including the suburi) to the file, however Rails routes aren't serving the files off of that path.
例如,<%= stylesheet_link_tag 'screen', :media => 'screen' %>
正确生成了代码<link href="/my-suburi/assets/screen.css" media="screen" rel="stylesheet" type="text/css" />
,但是Rails不会在该地址之外提供任何服务.
For instance, <%= stylesheet_link_tag 'screen', :media => 'screen' %>
correctly generates the code <link href="/my-suburi/assets/screen.css" media="screen" rel="stylesheet" type="text/css" />
, however Rails won't serve anything off of this address.
如果我将浏览器手动指向http://localhost:3000/my-suburi/assets/screen.css
,则会收到一个ActionController :: RoutingError.但是,如果我将其指向http://localhost:3000/assets/screen.css
,则会得到该文件. Sub-uri可以正常工作.
If I manually point my browser at http://localhost:3000/my-suburi/assets/screen.css
I get a ActionController::RoutingError. However, if I point it at http://localhost:3000/assets/screen.css
I get the file. Everything else works fine with the sub-uris.
有人知道我可能会缺少什么吗?谢谢.
Anybody have any idea what I might be missing? Thanks.
推荐答案
自己弄清楚了.在application.rb
中,我添加了...
Figured it out myself. In application.rb
, I added...
config.assets.prefix = "/my-suburi"
,然后重新启动服务器.将该标头中的路径更改为"/my-suburi/screen.css"
(注意缺少资产"),但我确认现在它已正确地从/app/assets/stylesheets文件夹中拉出.
and then restarted the server. That changed the path in the header to be "/my-suburi/screen.css"
(notice the lack of 'assets'), but I confirmed that it is correctly pulling from the /app/assets/stylesheets folder, now.
这篇关于具有Suburis的Rails 3.1资产管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!