LoginSignup
0
0

More than 3 years have passed since last update.

【簡潔】Railsで不要ファイルを生成しない方法~Ruby~

Last updated at Posted at 2020-05-10

概要

rails gコマンドでファイルを生成するときに不要なファイルを指定して生成しないようにする方法を解説します。


・方法

まずrails newで作成したアプリを開いて、configの中のapplication.rbを開きます。


そうすると以下のような画面が出てくると思います↓

config/application.rb
require_relative 'boot'
require 'rails/all'
Bundler.require(*Rails.groups)

module PostApp
  class Application < Rails::Application
    config.load_defaults 5.2
  end
end

この中の

config.load_defaults 5.2

の行のconfig.以下load_defaults 5.2を削除します。

そうしましたらconfig.後に生成したくないファイルについて記述します。


以下のように記述してください↓

config/application.rb
require_relative 'boot'
require 'rails/all'
Bundler.require(*Rails.groups)

module PostApp
  class Application < Rails::Application  
    config.generators do |g|
      g.javascripts false
      g.helper false
      g.test_framework false
    end
  end
end

このように記述すると生成したファイルに対応した
-javascripts
-helper (ヘルパー)
-test_framework (アプリをテストするためのファイル)
が生成されなくなります。





この記事を読んでいただきありがとうございました。

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