views:

135

answers:

2

I'm trying to use the jQuery Datepicker to set a date field in my Ruby on Rails form, but I can't work out how to do it. Can someone point me in the right direction?

A: 

Since Rails uses Prototype, you'll need to use jQuery in noConflict mode. Make sure you include jQuery after Prototype has been loaded using something similar to:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jqueryui.js"></script>
<script type="text/javascript">
  jQuery.noConflict();
  jQuery(document).ready(function($) {
    // here the $ function is jQuery's because it's an argument
    // to the ready handler
    $('#dateField').datepicker();
  });
  // here the $ function is Prototype's
</script>
tvanfosson
+1  A: 

Ryan Bates has a really great explanation of all of this:

http://railscasts.com/episodes/213-calendars

Christian Bankester