I know how to use jquery alone but since I am pretty new to Rails 3.1 I have only little idea how to integrate jquery into Rails.
So far I have come up with following steps but the first (naive) way of programing things are usually wrong 🙂
- datepicker plugin for jquery (e.g. jquery-ui-timepicker-addon.js) into app/assets/javascripts
- add line //= jquery-ui-timepicker-addon to application.js
- When I want date picker in some VIEW I will create app/assets/javascripts/VIEW.js and in there I will use standard jQuery to hook up date picker
Is there a more elegant way?
You can try this:
Add the jquery-ui .js file to the app/javascripts folder. Which you can download [here][1]
[1]: http://jqueryui.com/download. Maybe your jquery-ui-timepicker-addon.js will do as well.
You don’t need to add code to application.js. As all .js files in the javascripts folder
will be included and compiled automatically
Add the following line to
app/javascripts/{viewname}.js.coffee
$ -> $(‘.date’).datepicker()
The line above is the coffeescript equivalent of:
$(“#datepicker”).datepicker();