如何在rails 4.1中包含自定义资产

时间:2014-04-17 08:09:22

标签: ruby-on-rails ruby-on-rails-4.1

从4.0升级到4.1时出现javascript错误

我将ace-admin-themelenord-single-page-theme个文件夹放在app/assets/

并在config/application.rb

中添加以下内容
 29     config.assets.paths << "#{Rails.root}/app/assets/ace-admin-theme"
 30     config.assets.paths << "#{Rails.root}/app/assets/lenord-single-page-theme"




.
├── ace-admin-theme
│   ├── avatars
│   ├── css
│   ├── font
│   ├── images
│   ├── img
│   └── js
├── images
├── javascripts
│   └── application.js
├── lenord-single-page-theme
│   ├── css
│   ├── fonts
│   ├── img
│   ├── index.html
│   ├── js
│   └── rs-assets
└── stylesheets
    ├── application.css.scss
    ├── custom.css.scss
    ├── layout.css.scss
    ├── scaffolds.css.scss
    ├── users.css.scss
    └── welcome.css.scss

我需要在app/views/layouts/application.html.haml

中包含数百个css和javascript
  2 %html
  3   %head
  4     %title GooodTheme
  5     = stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true
  6     = javascript_include_tag "application", "data-turbolinks-track" => true
  7     / Description, Keywords and Author
 11     %meta{content: "width=device-width, initial-scale=1.0", name: "viewport"}/
 12     / Styles
 13     / Bootstrap CSS
 14     %link{href:  asset_path("css/bootstrap.min.css"), rel: "stylesheet"}/
 15     / Slider Revolution CSS
 16     %link{href:  asset_path("css/rs-settings.css"), rel: "stylesheet"}/

enter image description here

1 个答案:

答案 0 :(得分:0)

1)如果您的自定义文件夹属于标准资源路径(app / assets,lib / assets&amp; vendor / assets),那么您不需要config.assets.path。

2)将文件夹特定资产(如javascripts,css,images,fonts等)放在标准路径下。即。在资产/ javascripts

下的assets / css和javascripts下放置css