Skip to content

Add Datepicker in rails3 app

February 16, 2011

To add a external datepicker jquery file in our rails application

edit app/views/layouts/application.html.erb


<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css", "application" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "application" %>
<%= csrf_meta_tag %>
 <title>Inventory</title>
</head>

then app/views/products/_form.html.erb

edit f.date_select as f.text_field


<div>
 <%= f.label :purchased_on %><br />
 <%= f.text_field :purchased_on %>
 </div>

In javascript file to write a date picker function

public/javascripts/application.js


$(function (){
 $('#product_purchased_on').datepicker();
 });

then run your application

Advertisements
9 Comments leave one →
  1. July 18, 2011 8:29 pm

    There’s a small error in your code. It needs to be:

    $(‘#product_purchased_on’).datepicker();

    • Rajkumar.S permalink*
      July 18, 2011 9:40 pm

      thanks houen..
      And sorry for my mistake, now i changed it

  2. July 25, 2011 6:05 am

    I do this:

    TKD Arte Marcial

    “all” %>

    But in the top of the page appear la word => application

    What is the problem?
    I have rails 3

    poli

  3. July 25, 2011 6:05 am

    “I do this:

    TKD Arte Marcial

    “all” %>


    But in the top of the page appear la word => application

    What is the problem?
    I have rails 3

    poli

  4. July 25, 2011 6:14 am

    WordPress is capturing my code as html.
    My problem is that in the web page appear on the top the word ‘application’

    what’s happen?

  5. Arif Usman permalink
    November 10, 2011 5:49 pm

    Do I have to insert the gem for datepicker in my Gemfile as I get the text field but not the calendar.

  6. dayo permalink
    April 10, 2012 7:03 am

    Please this doesnt seem to work on rails 3.2, ive installed and tried it exactly as you described

  7. matreo permalink
    July 12, 2012 4:03 pm

    not working in rails 3.2.6

  8. matreo permalink
    July 13, 2012 10:51 am

    the date picker is not going to be visible.I followed all steps.using rails 3.2.6
    Is there any alternate way to do this?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: