Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleTable of Contents

Table of Contents


...

Examples - generate code for rails application

Code Block
languagenone
$ 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)

See also... Naming Conventions


Other less common uses for rails generate...

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

...