I have a form field in my Rails view:
<%= f.text_field :date, :class => "datepicker" %>
The javascript function converts all input fields of this class to jQueryUI datepicker.
$(".datepicker").datepicker({ dateFormat : "dd MM yy", buttonImageOnly : true, buttonImage : "<%= asset_path('iconDatePicker.gif') %>", showOn : "both", changeMonth : true, changeYear : true, yearRange : "c-20:c+5" })
So far so good. I can edit the record, and it correctly saves the date to the database. My problem is when I want to edit the record again. When the form is pre-populated from the record, it is displayed in the format "yyyy-mm-dd". Javascript only formats the dates selected in the datepicker control. Is there a way to format the date retrieved from the database? At what stage can I do this?
Thanks, Dani.
Below is a more detailed description of my form, which applies to two files, a view and a partial one. Here is the view:
<%= form_tag("/shows/update_individual", :method => "put") do %> <% for show in @shows %> <%= fields_for "shows[]", show do |f| %> <%= render "fields", :f => f %> <% end %> <% end %> <%= submit_tag "Submit"%> <% end %>
And here is a partial view of _fields :
<p> <%= f.label :name %> <%= f.text_field :name %> </p> <p> <%= f.date %> <%= f.label :date %> <%= f.text_field :date, :class => "datepicker" %> </p>
Controller Code:
def edit_individual @shows = Show.find(params[:show_ids]) end
I added the following to environment.rb :
Date::DATE_FORMATS.merge!( :default => "%d %B %Y" )
Now it displays the correct format when I use @ show.date in the view, but the form helper still displays the raw format.