select snippets

How to integrate the Any+Time jQuery date-select plugin with Rails

Tagged date, time, select, anytime, ruby, rails  Languages ruby

Add the following to your AR model:

def send_at_formatted
   self.send_at.strftime('%d.%m.%Y') if self.send_at?

def send_at_formatted=(value)
   self.send_at =

Add the following to your JavaScript file:

$(document).ready(function() {
  $('.date-select').each(function(index, element) {
    var elem = $(element),
        options = { format: '%d.%m.%Y', labelTitle:'title') };

    AnyTime.picker( elem.attr('id'), options );

Add this to your HAML/ERB view:

= f.text_field :send_at_formatted, :class => 'date-select', :"data-title" => 'Send at'

Download Any+Time JS and CSS files and include them in your head tag.