我在 Rails 中使用 jquery-ui-rails gem 包作为日期选择器。但它不起作用。 这是我的 Gemfile
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'jquery-ui-rails' # For use of datepicker
gem 'uglifier', '>= 1.0.3'
end
这是我的 application.js 文件
//= require jquery
//= require jquery_ujs
//= require jquery.ui.datepicker
//= require tree .
这是我的 appplication.css 文件
*= require jquery.ui.datepicker
*= require_self
*= require tree .
这是我的 home.html.erb 文件
<%= text_field_tag "created_at"%>
这是我的 home.js.coffee 文件
jQuery -> $("#created_at").datepicker()
这会产生这样的错误
TypeError: $(...).datepicker is not a function
[Break On This Error]
return $("#created_at").datepicker();
每当我点击 return $("#created_at").datepicker();这将产生此代码
(function() {
jQuery(function() {
return $("#created_at").datepicker();
});
}).call(this);
我认为我的咖啡纸是正确的。但为什么它给这个代码 return $("#created_at").datepicker();在 home.js 文件中。有谁对此有想法吗?请帮助我。
最佳答案
我认为这个 gem 包不起作用,所以我像这样在我的 application.htm.erb 中调用 jquery ui
<!DOCTYPE html>
<html>
<head>
<title>PV-NEC</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= javascript_include_tag "http://code.jquery.com/ui/1.10.3/jquery-ui.js" %>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
关于javascript - 我的 jquery-ui-rails CoffeeScript 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16593062/