Post

Ruby On Rails Prerequisites

Contains the necessary basics to get you up to speed

Generating a controller

1
$ rails generate controller StaticPages home help

Destroying a controller

1
$ rails destroy controller StaticPages home help

Generating a model

1
$ rails generate model User name:string email:string

Destroying a model

1
$ rails destroy model User

Initiating a database migration

1
$ rails db:migrate

Undoing a database migration

1
2
3
4
#Undoing a single migration
$ rails db:rollback
#Go back all the way to the beginning
$ rails db:migrate VERSION=0

Test-driven development (TDD) is a valuable tool to have in your kit. Here are a set of guidelines on when we should test first (or test at all):

  • When a test is especially short or simple compared to the application code it tests, lean toward writing the test first.

  • When the desired behavior isn’t yet crystal clear, lean toward writing the application code first, then write a test to codify the result.

  • Because security is a top priority, err on the side of writing tests of the security model first.

  • Whenever a bug is found, write a test to reproduce it and protect against regressions, then write the application code to fix it.

  • Lean against writing tests for code (such as detailed HTML structure) likely to change in the future.

  • Write tests before refactoring code, focusing on testing error-prone code that’s especially likely to break.

This post is licensed under CC BY 4.0 by the author.

Trending Tags