0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Rails】application.rbについて

Last updated at Posted at 2025-05-18

記事概要

Ruby on Railsの設定ファイルについて、まとめる

前提

  • Ruby on Railsでアプリケーションを作成している

基本情報

ファイルパス

config/application.rb

まとめ

コントローラー生成時に不要なファイルを生成しない

rails gコマンドでコントローラーを作成すると、自動で関連ファイルが作成されるが、ファイルを自動生成しないように設定する

application.rb
config.generators do |g|
  # 生成したファイルに対応したスタイルシートを生成しない
  g.stylesheets false
  # 生成したファイルに対応したJavaScriptファイルを生成しない
  g.javascripts false
  # 生成したファイルに対応したヘルパーを生成しない
  g.helper false
  # アプリケーションをテストするためのファイルを生成しない
  g.test_framework false
end

デフォルトの言語設定

config.i18n.default_locale = :jaを追記することで、デフォルトの言語を日本語に変更できる
deviseのエラーメッセージも日本語化するよう求められる

application.rb
module アプリ名
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 7.1
    
    # アプリのデフォルトの言語設定を日本語に変更
    config.i18n.default_locale = :ja
    # 省略
  end
end

デフォルトのタイムゾーン設定

config.time_zone = 'Tokyo'を追記することで、東京のタイムゾーンに変更できる

application.rb
module アプリ名
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 7.1
    
    # アプリのデフォルトのタイムゾーン設定を東京に変更
    config.time_zone = 'Tokyo'
    # 省略
  end
end

コントローラー

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?