views:

356

answers:

4

I have a rails form that that displays a date in a text_field:

<%= form.text_field :check_in_date %>

The date is rendered at yyyy-mm-dd

I'm trying to figure out how to have it display as mm-dd-yyyy

I tried adding this config but it didn't work.

ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(
  :default => '%m/%d/%Y'
)
A: 

Go to your environment.rb file and add the following:

ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(
  :default => '%m-%d-%Y' )

Check the official documentation if you feel like reading more :)

Konstantinos
A: 

If you can set the value manually you can use created_at.strftime("%m-%d-%Y") http://snippets.dzone.com/tag/strftime .

ThinkBohemian
+1  A: 

config/initializers/date_format.rb

ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS[:default]='%m/%d/%Y'

view

<%= form.text_field :check_in_date, :value => model.check_in_date.to_s %>

Felix Flores