We're going to use this post as a place to store the running list of commands that I need fairly routinely when developing on rails, but tend to forget the specific syntax. Everything that gets done on the rails console belongs here, we'll try to organize it as we add to it:
Gem Stuff:
to install your gem bundle: bundle install
Ruby at the command line:
Run ruby from the command line: rails console
Start your app: bin/server
generate a migration file: rails generate model Thingy name:string description:text
migrate the built database: rails db:migrate
(Here is a good general resource for migrations: https://guides.rubyonrails.org/v3.2/migrations.html)
Scaffolding! Build a new DB with all the commands and stuff ready to go: rails g scaffold
A scaffold is a set of automatically generated files which forms the basic structure of a Rails project. Scaffold is the same thing as generating a migration, but using the scaffold
syntax tells rails to set up the associated db files. You could technically write it all in yourself after doing a rails generate migration
, but using scaffold
is a shortcut that saves you a lot of thinking and typing.
These scaffold files include:
- A controller
- A model
- Views for every standard controller action (index, edit, show, new)
- A new route.
- A migration to prepare your database.
Top comments (0)