【问题标题】:cannot find //=require jquery.nouislider in application.css在 application.css 中找不到 //=require jquery.nouislider
【发布时间】:2014-06-07 11:00:41
【问题描述】:

我正在尝试使用一些滑块宝石,但我一直遇到同样的问题,

https://github.com/soycamo/jquery-nouislider-rails

我按照说明放入 app/assets/javascript 清单文件:

//=需要 jquery.nouislider

在 app/assets/stylesheets 清单文件中:

//=需要 jquery.nouislider

我还安装了 gem。但是我不断收到错误消息:

Showing /home/ubuntu/foodin/app/views/layouts/application.html.erb where line #8 raised: 
couldn't find file 'jquery.nouislider'
(in /home/ubuntu/foodin/app/assets/stylesheets/application.css:16)

<%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true %>

我认为这可能与资产管道有关,但我不确定。有任何想法吗?感谢您的帮助!

编辑:这是我的 development.rb 配置文件,以防它与此有关:

Foodin::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = false

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

#NEW: Added for Devise
config.action_mailer.default_url_options = { :host => 'localhost:3000' }

#New:Added for development
config.serve_static_assets = false

end

【问题讨论】:

  • 刚安装gem可能需要重启服务器
  • 试过了,但我仍然收到下面描述的错误:s
  • Gem 存在一些问题。它也不适合我。通过下载文件并保存在相应的资产目录中使用。
  • 您的意思是下载 gem 还是使用 javascript 文件手动完成?
  • 是的,不幸的是你必须这样做

标签: javascript css ruby-on-rails pipeline assets


【解决方案1】:

应该在 app/assets/stylesheets/application.css 中

*= require jquery.nouislider

而不是

//= require jquery.nouislider

并尝试将 Gemfile 声明替换为;

gem 'jquery-nouislider-rails', '~&gt; 4.0.1.1'指定版本并重启服务器

工作设置

我简单的 downloaded nonuislider here 并将其添加到 app/assets/javascripts 文件夹中,然后像您之前所做的那样在 application.js 中调用它并且它起作用了。也许宝石有问题。

【讨论】:

  • 我已经进行了更改,现在它给了我一个类似的 js 文件错误 - 显示 /home/ubuntu/foodin/app/views/layouts/application.html.erb 其中第 9 行出现:找不到文件'jquery.nouislider'(在/home/ubuntu/foodin/app/assets/javascripts/application.js:18)
  • 那行是这样的: true %>
  • 感谢您的建议,但似乎没有什么不同
  • 试试//= require jquery.nouislider文件名和声明之间的空格
  • 不走运,我确定它真的很简单,但我只是不知道它是什么:s
【解决方案2】:

不确定,但您的 Gem 似乎不是最新的。

你可以试试这个 fork 的 noUiSlider:

https://github.com/chug2k/nouislider-rails

或者这个对于 Seiyria 的滑块:

https://rubygems.org/gems/bootstrap-slider-rails/versions/6.0.17

滑动愉快:-)

【讨论】:

    猜你喜欢
    • 2021-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 2016-08-11
    • 2016-06-04
    • 2017-10-11
    • 2016-03-15
    相关资源
    最近更新 更多