Rails DatePicker - Object [object Object] has no method 'datepicker'

帅比萌擦擦* 提交于 2019-12-25 08:25:29

问题


I'm trying to add datepicker to my rails 3.2.8 application.

Since it is rails 3+, I didn't add anything to the application.html.erb.

My application.js is the following:

// 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();
});

And in views/transactions/_form.html.erb

I have:

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

But still, datepicker doesn't work and gives:

TypeError: Object [object Object] has no method 'datepicker'

error

That would be great if you can help me.

Thanks,


回答1:


According to this Railscast , you should add the datepicker component explicitly both in your application.js and application.css .

In application.js:

//= require jquery.ui.datepicker

and in application.css:

*= require jquery.ui.datepicker



回答2:


Maybe this gem can help you => https://github.com/joliss/jquery-ui-rails



来源:https://stackoverflow.com/questions/13351173/rails-datepicker-object-object-object-has-no-method-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!