1

我在我的 Rails 中使用 jquery-ui-rails gem 包作为 datepicker。但它不起作用。这是我的 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();

每当我点击返回 $("#created_at").datepicker(); 这将产生此代码

(function() {
jQuery(function() {
return $("#created_at").datepicker();
});
}).call(this);

我认为我的咖啡纸是正确的。但是为什么它给这个代码 return $("#created_at").datepicker(); 在 home.js 文件中。有没有人对此有想法。请帮我。

4

1 回答 1

0

我认为这个 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>
于 2013-05-30T13:59:12.433 回答