TLDR 1:

You can disable scaffolds from generating certain files in your app config:

# config/application.rb
module Myapp
  class Application < Rails::Application
+    config.generators do |g|
+      g.assets false
+      g.helper false
+      g.test_framework false
+      g.jbuilder false
+    end
  end
end

TLDR 2: add a few --no tags to your rails generators to produce only the crucial files:

rails g controller home index --no-helper --no-assets --no-controller-specs --no-view-specs --no-test-framework

rails g scaffold product name description:text --no-helper --no-assets --no-controller-specs --no-view-specs --no-test-framework --no-jbuilder


Now, Let’s dive in and make our rails generators cleaner!

Skinny Scaffold Generator

A usual scaffold like

rails g scaffold product name description:text

produces:

  • Migration
  • Model
  • View
  • Controller
  • Tests
  • Helpers
  • Stylesheets
  • jbuilder

dirty scaffold

That’s a lot! However you won’t be needing most of these in most hobby applications.

A shorter scaffold would be:

rails g scaffold product name description:text --no-helper --no-assets --no-controller-specs --no-view-specs --no-test-framework --no-jbuilder

that produces:

  • Migration
  • Model
  • View
  • Controller

clean scaffold

Much cleaner! Bravo!

Skinny Controller Generator

A usual command like

rails g controller home index

produces:

  • Controller
  • Views
  • Helper
  • Stylesheet
  • Tests

dirty controller generator

That’s a lot! And you won’t need most of it for a basic hobby app!

Let’s modify our generator and run:

rails g controller home index --no-helper --no-assets --no-controller-specs --no-view-specs --no-test-framework

That produces only:

  • Controller
  • Views

clean controller generator

Much cleaner, and does not create mess that you will likely not be using!


Relevant links

rails g scaffold product name description:text

rails g scaffold product name description:text --no-helper --no-assets --no-controller-specs --no-view-specs --no-test-framework --no-jbuilder