views:

198

answers:

1

Hi,

I have an input field that captures a date in my form

<%= f.text_field :from_date, :style => 'width:80px;' %>

The user enters the date in the following format MM/DD/YYYY. However, when there is a validation error in the model and the form is displayed back to the user with the entered values, the date format is converted to YYYY-MM-DD HH:MM:SS UTC. Where do I format this to show MM/DD/YYYY, when the form is displayed to the user.

thanks.

A: 

Try following & put your date in place of the @date <%= f.text_field :from_date, :style => 'width:80px;', :value=>(@date.blank?)? '' : @date.strftime('%m/%d/Y') %>

Salil
I am guessing there should be some rails configuration setup for default formats for these kind of things.
yes there are number of helpers/plugins for dates.but you are using the text field so i guess that is the best answer i know.For date you should used date_select of rails OR search calendar_date_select plugin for rails
Salil