简体   繁体   中英

rails date field format on error

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.

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') %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM