javascript Ruby on Rails:“找不到文件‘jquery.ui.datepicker’”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19171470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ruby on Rails: "couldn't find file 'jquery.ui.datepicker'"
提问by krstck
Okay, this is driving me nuts. I've been following the instructions to install a JQuery datepicker here: http://railscasts.com/episodes/213-calendars-revisedbut I'm getting hung up on this error:
好吧,这让我发疯。我一直在按照说明在这里安装 JQuery 日期选择器:http://railscasts.com/episodes/213-calendars-revised但我被这个错误挂了:
Sprockets::FileNotFound in Verifications#new
couldn't find file 'jquery.ui.datepicker'
(in /app/assets/stylesheets/application.css:11)
Here's application.js:
这是 application.js:
//= require jquery
//= require jquery.ui.all
//= require jquery_ujs
//= require_tree .
Here's application.css:
这是 application.css:
*= require jquery.ui.datepicker
*= require_self
*= require_tree .
and in Gemfile:
在 Gemfile 中:
group :assets do
gem 'jquery-ui-rails'
end
Anyone see what I'm missing?
有人看到我缺少什么吗?
回答by seancdavis
For future readers. First, make sure you've restarted your rails server after installing the gem as krstck answered.
对于未来的读者。首先,确保在 krstck 回答安装 gem 后重新启动了 Rails 服务器。
Then, double check the version of your gem. jquery-ui-rails
has changed its require
syntax in 5.0.0
. Now you should write:
然后,仔细检查您的 gem 的版本。jquery-ui-rails
已更改其require
语法5.0.0
。现在你应该写:
//= require jquery-ui/datepicker
Also add to css
也添加到css
*= require jquery-ui/datepicker
回答by krstck
Answering my own question here in case someone else makes the same dumb mistake. I restarted the rails server, and then it worked.
在这里回答我自己的问题,以防其他人犯同样的愚蠢错误。我重新启动了 rails 服务器,然后它工作了。
回答by Luka Kerr
For Rails 5 users, to use the jQuery
datepicker you must add this to your application.js
:
对于 Rails 5 用户,要使用jQuery
日期选择器,您必须将其添加到您的application.js
:
//= require jquery-ui/widgets/datepicker
And this to your application.css
:
这给你的application.css
:
/*
*= require jquery-ui/datepicker
*/
You can also just use the usual gem version:
您也可以只使用通常的 gem 版本:
gem 'jquery-ui-rails'
Restart your server as well.
也重启你的服务器。
Here is the documentation
这是文档
回答by felipecamposclarke
adds 'jquery-ui-rails' on your Gemfile, and use a hyphen instead of a point to require jquery-ui
在您的 Gemfile 上添加“jquery-ui-rails”,并使用连字符而不是点来要求 jquery-ui
//= require jquery-ui
or downgrade the jquery-ui gem version
或者降级 jquery-ui gem 版本
gem 'jquery-ui-rails', '~> 4.2.1'
回答by Kris Quigley
Downgrading from jquery-ui-rails 5.0.0 to 4.2.1 fixed it for me.
从 jquery-ui-rails 5.0.0 降级到 4.2.1 为我修复了它。
回答by Jelle
Just to add to this: I had the same issue, I finally solved it by placing //= require turbolinks
before the jquery requirements in application.js
:
补充一点:我遇到了同样的问题,我最终通过将其放在//= require turbolinks
jquery 要求之前解决了这个问题application.js
:
//= require turbolinks
//= require jquery
//= require jquery.ui.datepicker
//= require jquery_ujs
//= require_tree .