What is the difference between rails g scaffold vs model vs resource

What is the difference between rails g: (a) scaffold vs (b) model vs (c) resource?

This article assumes that you have some familiarity with rails. So it’s gonna be short and sweet.

Model

rails g model Product name
  • By rails convention the name is assumed to be a string.

This creates:

  1. A model and
  2. A migration file

Resource

Is the same as above, but in addition it generates:

  1. a controller and
  2. adds the appropriate routes.

Scaffold

Adds the same as the above two, except it also adds:

  1. Views

Omissions

I have ignored the creation of test specs, assets and helpers which may be created when generating the above. If you don’t want them created you can use an option to stop them being created:

rails generate controller home index  --no-helper --no-assets --no-controller-specs --no-view-specs
Written on January 22, 2017