This file lists several common commands that you may find useful in
the Ruby on Rails projects for CS142. In most cases you should run these
commands in the top-level directory for a Rails application (exceptions:
"rails new
", which creates a new application, and
gem
).
rails new foo
Creates a new Rails applications in subdirectory foo
.
rails server
Starts up a Web server on port 3000 running the current application; log messages from the server will appear on standard output.
rails generate controller foo a b
Creates a new controller class FooController
with a
skeleton class
definition in app/controllers/foo_controller.rb
. It also
creates skeleton action methods a
and b
in the controller, plus skeleton views in the files
app/views/foo/a.html.erb
and app/views/foo/a.html.erb
.
If a
and b
are omitted then the controller is
created with no actions or views.
rails generate model foo
Creates a new model class Foo
with a skeleton class
definition in app/models/foo.rb
and a skeletal migration
in db/migrate/*_create_foos.rb
.
rails generate migration foo
Creates a new migration in the file db/migrate/*_foo.rb
.
rake db:migrate
Runs all migrations to bring the database up to date.
rake db:migrate:reset
Drops the database, creates a new one, and runs all migrations to bring the database up to date.
rake db:migrate VERSION=20090909201633_create_photos.rb
Runs migrations (either forward or backward) to restore the database to match the state just after the given migration.
gem update
Updates all Ruby Gems.
gem update rails--include-dependencies
Updates Rails to the latest version, including all Gems that Rails depends upon.
gem update --system
Updates Ruby to the latest version. This command does not always appear to work on Macintoshes.