【问题标题】:My coffeescript for jquery-ui-rails is not working我的 jquery-ui-rails 咖啡脚本不工作
【发布时间】:2013-05-16 16:43:11
【问题描述】:

我在我的 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 文件中。有没有人对此有想法。请帮帮我。

【问题讨论】:

    标签: javascript jquery-ui ruby-on-rails-3.2 gem coffeescript


    【解决方案1】:

    我认为这个 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>
    

    【讨论】:

      猜你喜欢
      • 2018-01-25
      • 2015-08-03
      • 2011-11-08
      • 2014-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多