Rails DatePicker – 对象没有方法’datepicker’

我正在尝试将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中

我有:

 

但仍然,datepicker不起作用,并给出:

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

错误

如果你可以帮助我,那将是很棒的。

谢谢,

根据这个Railscast ,您应该在application.js和application.css中明确添加datepicker组件。

在application.js中:

 //= require jquery.ui.datepicker 

并在application.css中:

 *= require jquery.ui.datepicker 

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