【问题标题】:Rails is not finding vendor/assets in Rails 4.0.x in development mode?Rails 在开发模式下找不到 Rails 4.0.x 中的供应商/资产?
【发布时间】:2014-03-22 01:59:05
【问题描述】:

我有以下设置:

gem 'rails', '~> 4.0.3'

config/application.rb:

 config.assets.paths << Rails.root.join('vendor', 'assets', 'components')

vendor/assets/components/gridster/dist:

jquery.gridster.min.css  jquery.gridster.with-extras.min.js
jquery.gridster.min.js

然而,一旦我转到 http://localhost:3000/ 并在浏览器中查看源代码,这些资产并没有显示出来......我必须怎么做才能让它们出现?

更新:

application.js:

//= require jquery
//= require jquery_ujs
//= require jquery.validate
//= require bootstrap
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap3
//= require jquery.gridster.min
//= require jquery.gridster.with-extras.min
//= require_tree .

application.css.scss:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the top of the
 * compiled file, but it's generally better to create a new file per style scope.
 *
 *= require_self
 *= require dataTables/jquery.dataTables
 *= require dataTables/jquery.dataTables.bootstrap3
 *= require jquery.gridster.min
 *= require_tree .
 */

【问题讨论】:

  • 您可以发布您的application.js 清单吗?你可能忘了把它们放在那里。你应该可以做类似//= require_tree gridster
  • 是的,我忘了把它放在application.js中

标签: ruby-on-rails ruby-on-rails-4 asset-pipeline


【解决方案1】:

在 application.js 中,添加以下行

//= require gridster/dist/jquery.gridster.min
//= require gridster/dist/jquery.gridster.with-extras.min

在 application.css 中,添加以下行

*= require gridster/dist/jquery.gridster.min

您需要添加文件的 reference,以便 Sprockets 搜索默认资产位置,即 app/assetslib/assetsvendor/assets 以及附加到 config.assets.paths 的任何其他路径

【讨论】:

  • 感谢 Kirti,不幸的是,我得到 Sprockets::FileNotFound at.... 找不到文件 'jquery.gridster.min'(请参阅更新)。因为我有 config.assets.paths
  • @Bruce 看到我更新的答案。您需要提供 js 文件的路径,因为它不直接存在于 components 文件夹中。
  • 谢谢@Kirti - 它成功了!你也不知道为什么我不能像在 - //=require/gridster/dist/* 中那样使用“*”运算符?
  • 我不确定你到底想在哪里使用引号。如果传递给 require 指令的参数有空格,则可以使用引号。然后,您可以将参数括在空格中,例如 //= require "my custom jquery" for a "my custom jquery.js" file
  • 我想你可能想做 require_tree /gridster/dist 而不是 require /gridster/dist/*
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-19
相关资源
最近更新 更多