【问题标题】:Add a two different asset path in Rails 3.2在 Rails 3.2 中添加两个不同的资产路径
【发布时间】:2013-01-09 06:03:15
【问题描述】:

我喜欢在我的 rails 3 应用程序中使用两个不同的 assets 文件夹。我喜欢从 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" />

在生产中添加了.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 并且在浏览器中没有发生任何变化。请帮我解决。

【问题讨论】:

    标签: ruby-on-rails-3 ruby-on-rails-3.2 asset-pipeline


    【解决方案1】:

    我认为您对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-08-27
      • 1970-01-01
      • 2014-07-30
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 1970-01-01
      相关资源
      最近更新 更多