How to correct "rails generate" errors easily - Lesson learned 1

Yesterday I made a mistake and created controller with singular name instead of Plural name.

$rails generate controller Ticket

Then I realized my mistake and wanted to delete bunch of files that got created.

Easy way to delete all the files is as follows:

$rails destroy controller Ticket
$rails generate controller Tickets

It's worth mentioning the -p flag here ("p" for pretend).

If you add this to the command it will simply do a "test" run and show you what files will be deleted without actually deleting them.

$rails destroy controller Ticket -p
$rails destroy controller Ticket

Similarly, you can destroy incorrect model and scaffold code.
$rails destroy model Lalalala
$rails destroy scaffold hohoho

Design your web app in following order.

1. Model: $rails generate model Article title:string (model name is Article. Use singular word with first letter Capitalized.)

2. $rake db:migrate to build database table.

3. Controller: $rails generate controller Articles (Use plural word with first letter Capitalized.)

4. Fix config/routes.rb to add resources.

5. $rake routes to check that correct routes are created.

6. View:

 

Rating: