Change date format in Rails form

Asked

Viewed 1,228 times

0

I know there is how to edit in the location, to pass it to the Brazilian format. But I do not know the syntax to change the format in the form:

  <div class="field">
    <p> Garantia </p>
    <%= f.date_select :guarantee %>
  </div>
  • Look if it can help you. http://stackoverflow.com/questions/1449955/rails-date-format-in-a-text-field

  • I think this is an HTML issue, isn’t it? What kind of input does the date_select generates?

  • Managed to solve the problem?

  • @ygorbr Managed to solve the problem?

2 answers

2


Put in your config/application.rb

 Time::DATE_FORMATS[:default] = "%d/%m/%Y %H:%M"
 Date::DATE_FORMATS[:default] = "%d/%m/%Y"

That the formatting of all system dates go to the Brazilian standard.

  • 1

    Thank you Luiz Carvalho. Problem solved.

-1

I was looking about dates and dropped here, for you to use in the Brazilian long format with the I18n is very interesting:

I18n.l(Time.now, format: "%d de %B de %Y") # 27 de fevereiro de 2021

Browser other questions tagged

You are not signed in. Login or sign up in order to post.