¶ ↑
jQuery Datepicker Rails pluginThis simple gem allows you to add a date picker field into your views.
¶ ↑
Getting StartedPre Rails 3.1:
-
Add into your Gemfile:
gem 'jquery-rails'
-
Execute this command to install the needed js files:
rails generate jquery:install --ui
-
Insert into your Gemfile:
gem 'jquery_datepicker'
Don't forget to install the CSS!
Rails 3.1:
-
Insert into your Gemfile:
gem 'jquery_datepicker'
-
If you are using Rails 3.1 with the asset pipeline enabled (default), the necessary files are already in your asset pipeline. Just add (if they are not already there) to your app/assets/javascripts/application.js:
//= require jquery //= require jquery-ujs //= require jquery-ui
¶ ↑
UsageAdd this to your view.
<%= datepicker_input "user","birthday" %>
Where “user” is your model name and “birthday” the name of the datefield.
You can also use it with the form helper like:
<% form_for(@user) do |f| %> <%= f.datepicker 'birthday' %> <%= f.submit 'Create' %> <% end %>
Nested attributes are permitted as well:
<% form_for(@user) do |f| %> <% f.fields_for(@nested) do |f2| %> <%= f2.datepicker 'birthday' %> <% end %> <%= f.submit 'Create' %> <% end %>
You can pass options as it would be a normal text_field, plus all the datepicker options available (jqueryui.com/demos/datepicker/#options)
<%= datepicker_input(:foo, :att1, :minDate => -20, :maxDate => "+1M +10D", :tabindex => 70) %>
¶ ↑
SupportOpen an issue in github.com/albertopq/jquery_datepicker if you need further support or want to report a bug