Rails Datepickers

There are multiple ways to add date-pickers to a Rails application. Searching for a date picker online I came across one Prototype based gem called calendar_date_select that was featured by Ruby Inside, and another one called Calendar-DatePicker-for-Rails.  On closer inspection, however, calendar_date_select was last updated in 2008 and is looking for a new maintainer: the demo still uses Rails 2.2.2: it does not work with some later versions.

Apart from using a date-picker specifically packaged for Rails it is not that difficult to use a free-standing Javascript solution: I found a nice looking solution called unobtrusive-date-picker but it appears to have limited support. There are also Javascript widget libraries like AUI and jQuery UI.  Finally I came across a Railscast that mentions calendar_date_select but goes on to recommends jQuery UI.  jQuery can be integrated with Rails 2.x using jRails or Rails 3 with jquery-rails and/or jquery-ujs or you can simply forgo the integration and just use jQuery directly. In my case I linked to the libraries hosted by Google like this:

 <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js" %>
 <%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/humanity/jquery-ui.css" %>

The remaining details of using a jQuery UI datepicker with Rails are covered in the Railscast.

Scroll to top