今回は、超絶簡単。
config.time_zone = 'Asia/Tokyo'
を追加するだけです!
[ config/application.rb ]
require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module TodoApp class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 6.0 config.time_zone = 'Asia/Tokyo' # 追加 # 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 end
以上!
変更後 ->
表示形式を変更する
l メソッド
を使います
まず、config/application.rb
にtime_zone
とi18n
を設定します。
require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module TodoApp class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 6.0 config.time_zone = 'Asia/Tokyo' config.i18n.default_locale = :ja # 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 end
そしたら、ja.yml
に変更を加える
[ config/locales/ja.yml ]
ja: ~~~~~~~ time: formats: default: "%Y年%m月%d日"
フォーマットは自由に設定できます。
あとは、各ビューページの表示したい場所にl
をつけるだけです。
tbody - @tasks.each do |task| tr td = task.done? ? 'Done' : 'Todo' td = link_to task.title, task td = l task.created_at td = l task.updated_at td
こんな感じ〜
以上だ