What type of functionalities do the different generators generate in Rails?

28 views
Skip to first unread message

songs

unread,
Feb 25, 2018, 1:28:45 AM2/25/18
to Ruby on Rails: Documentation
Hey folks, 

So I'm quite the newbie here as y'all can tell. 

Prior to asking this question as referenced in subject, I read the guide at http://guides.rubyonrails.org/command_line.html#rails-generate but was not able to find the answer to my question, in spite of then trying to search for more online resources. 

What I'm wondering is, if there's a way for me for e.g. to type some command within the Mac's terminal to output functionalities that all generators generate (for e.g. scaffold would generate CRUD functionality, and controller would generate pages functionality, etc)

Objective: to know which generator to use, to generate desired features of any app   

Much thanks 

Filipe W. Lima

unread,
Mar 3, 2018, 4:23:18 AM3/3/18
to Ruby on Rails: Documentation
Hey, Songs. Welcome to the group discussion.

I'm not sure I really understood what you're asking though. 😕

output functionalities that all generators generate

If you want to see the list of possible `generate` commands, you can run `rails generate` in the terminal. For more information about a particular generator, you can append `--help` (e.g. `rails generate migration --help`). I don't know if that's what you're looking for because you mentioned to having read the Rails Guides. If you don't really know what each of them really do, as a beginner, I recommend you to read the details for at least `migration` and `scaffold`. As your expertise grows, you may eventually find yourself depending less on the use of scaffolding.

Try some of the generators yourself. You can always undo the generated files by running the same command, but using `destroy` instead of `generate` (e.g. `rails destroy model post`).

SoliPet

unread,
Mar 3, 2018, 4:23:18 AM3/3/18
to Ruby on Rails: Documentation
If you run

$ rails generate --help
 
it will list out all of the generators built in to rails.  To learn what any individual generator does, type

$ rails generate <generator> --help

for example:

$ rails generate scaffold --help
Running via Spring preloader in process 12695
Usage:
  rails generate scaffold NAME [field[:type][:index] field[:type][:index]] [options]
...

Running a generator with -p will have it show you what it would do, without making actually making any changes, e.g.,

$ rails generate scaffold foo -p
Running via Spring preloader in process 12858
      invoke  active_record
      create    db/migrate/20180301205059_create_foos.rb
      create    app/models/foo.rb
      invoke    rspec
      create      spec/models/foo_spec.rb
... 
Reply all
Reply to author
Forward
0 new messages