【问题标题】:Rails DatePicker - Object [object Object] has no method 'datepicker'Rails DatePicker - 对象[对象对象]没有方法'datepicker'
【发布时间】:2012-11-12 20:36:57
【问题描述】:

我正在尝试将 datepicker 添加到我的 rails 3.2.8 应用程序中。

由于是 rails 3+,我没有在 application.html.erb 中添加任何内容。

我的 application.js 如下:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .

$(function(){
    $("#transaction_deadline").datepicker();
});

在views/transactions/_form.html.erb中

我有:

<div class="field">
    <%= f.label :deadline %><br />
    <%= f.text_field :deadline %>
  </div>

但是,日期选择器仍然不起作用并给出:

TypeError: Object [object Object] 没有方法 'datepicker'

错误

如果你能帮助我,那就太好了。

谢谢,

【问题讨论】:

  • 你在导入 jQuery UI 库吗?或者至少是 datepicker 小部件?
  • 这些不是用“ " 代码导入的吗?
  • 我在问,你是在导入 jQuery UI/datepicker 和 jQuery 库吗?
  • 是的,我猜这些行:ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/…", "application" %> ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "application" %>

标签: jquery ruby-on-rails datepicker


【解决方案1】:

也许这个宝石可以帮助你 => https://github.com/joliss/jquery-ui-rails

【讨论】:

    【解决方案2】:

    根据Railscast,您应该在 application.js 和 application.css 中显式添加 datepicker 组件。

    在 application.js 中:

    //= require jquery.ui.datepicker
    

    在 application.css 中:

    *= require jquery.ui.datepicker
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多