I want to display a custom date format in rails 4 by calling something like:
@reveiw.created_at.to_s(:submitted)
So far I have tried:
Time::DATE_FORMATS(:submitted) = "%b %d %Y"
in my config/environment.rb and config/initializers/time_formats.rb files.
I have also added the following code to my config/locales/en.yml file
en:
time:
formats:
submitted: "%b %d %Y"
I have not had success. Is there a definitive strategy for rails 4?
If you want to use @review.created_at.to_s(:submitted)
, I think you need to use Time::DATE_FORMATS[:submitted] = "%b %d %Y"
(use square brackets instead of parentheses)
I believe the localization file output format is usable through Rails' #l
helper http://guides.rubyonrails.org/i18n.html#adding-date-time-formats. So <%= l review.created_at, format: :submitted %>
should work in an erb
view
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With