Rails 5 - Set Default DateTime Formats Across the Application
Scenario: You have a preferred default time format you want to use in your app and you need a way to capture this.
Fix: Add the format you want to use to the config/locales/en.yml file
time:
formats:
default: '%d/%m/%Y'
Now you can use the l helper method in your views or wherever you like (prefix with i18n module where you need to) and it will pick up this format.
<%= l(@transaction.transaction_date) %>
You can also specify a named format to use where you like too:
time:
formats:
fun: '%d-%m-%Y'
Then we can use it like so:
<%= l(@transaction.transaction_date), format: :fun %>