1

我喜欢在我的 rails 3 应用程序中使用两个不同的资产文件夹。我喜欢从 app/assets/ 以及 public/template/style1 提供服务。


- app
   - assets
     - javascripts
     - stylesheets
       - **styles.css**
     - images
   - controllers
   - models
   - ----
- public
 - template
   - style1
     - js
     - css
       - **theme.css**
     - img

布局文件

<%= stylesheet_link_tag "styles", :media => 'screen' %>

在使用 iframe 的同一页面中,喜欢使用来自 public/template/style1/css/theme.css 的样式

<link href="/template/style1/css/theme.css" media="screen" rel="stylesheet" type="text/css" />

在 production.rb 添加

config.assets.precompile += %w(styles.css)
config.assets.paths << "#{Rails.root}/public/template/style1/css"
config.assets.precompile += %w(theme.css)

我运行 rake assets:precompile 并且在浏览器中没有发生任何变化。请帮我解决。

4

1 回答 1

0

我认为您对theme.css文件的引用不正确。如果您在production.rb添加路径时声明"#{Rails.root}/public/template/style1/css",您应该像这样引用其中的内容:

<link href="theme.css" media="screen" rel="stylesheet" type="text/css" />

您可以考虑遵守有关资产管道的“约定”:将资产放在assets目录中。

一个更小的细节:如果您想使资产资源由资产管道管理,您只需在application.css文件中声明,如下所示:

 *= require theme 
于 2013-01-12T11:03:36.180 回答