ALL HOW TOs




Examples - generate code for rails application

$ rails g controller HighScores                  # creates controller app/controller/high_score_controller.rb with class HighScoreController; creates empty app/view/high_scores directory
$ rails g controller HighScores index list       # creates controller app/controller/high_score_controller.rb with class HighScoreController; creates app/view/high_scores/index.html.erb, list.html.erb

$ rails g migration HighScoreAddColumnAvgScore   # create migration db/migrate/_DTSTAMP_high_score_add_column_avg_score.rb with class HighScoreAddColumnAvgScore

$ rails g model HighScore                        # creates model app/model/high_score.rb with class HighScore; db/migrate/_DTSTAMP_create_high_scores.rb with class CreateHighScores

$ rails g scaffold HighScore game:string score:integer  # creates model, views, controller, migration  (see [rails g scaffold|~elr37:rails generate scaffold] for details)


Other less common uses for rails generate...

  • assets
  • generator
  • helper
  • integration_test
  • jbuilder
  • mailer
  • resource
  • scaffold_controller
  • task


Command Reference

Usage: rails generate GENERATOR [args] [options]

General options:
  -h, [--help]     # Print generator's options and usage
  -p, [--pretend]  # Run but do not make any changes
  -f, [--force]    # Overwrite files that already exist
  -s, [--skip]     # Skip files that already exist
  -q, [--quiet]    # Suppress status output

Please choose a generator below.

Rails:
  assets
  controller
  generator
  helper
  integration_test
  jbuilder
  mailer
  migration
  model
  resource
  scaffold
  scaffold_controller
  task

Coffee:
  coffee:assets

Jquery:
  jquery:install

Js:
  js:assets

TestUnit:
  test_unit:generator
  test_unit:plugin
  • No labels