Not the default notation September 2020 ◯◯ day and 2020/09/◯◯ Change to 11:05 or 11:05
ruby 2.5.7 Rails 5.2.4.3 OS: macOS Catalina
Introduced 1 gem'rails-i18n' 2 Edit config / application.rb 3 Change view
Gemfile
gem 'rails-i18n'
Terminal
$ bundle install
Add the following 4 lines to config.load_defaults.
config/application.rb
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
config.paths.add 'lib', eager_load: true
config.time_zone = 'Tokyo'
config.i18n.default_locale = :ja
config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
end
It is OK if you write as follows.
erb:app/views/posts/show.html.erb
<%= @post.updated_at.strftime("%Y year%m month%d day").to_s %>
<%= @post.updated_at.strftime("%Y/%m/%d").to_s %>
<%= @post.created_at.strftime("%H o'clock%M minutes").to_s %>
<%= @post.created_at.strftime("%H:%M").to_s %>
If you use gem'rails-i18n', you can also write the error in Japanese. For more information here
Recommended Posts