Uday's website
Published on Uday's website (https://uday.net)

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

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

Submitted by uday [2] on August 19, 2020 - 2:27pm

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: 
Tags: 
Rails [3]

 Valid XHTML 1.0 StrictCreative Commons LicenseVerbatim copying and redistribution of this entire page are permitted provided this notice is preserved. All content on this website including archives (including text, photographs, audio files and any other original work), unless otherwise noted, is licensed under a Creative Commons License or later.


Source URL:https://uday.net/How-to-correct-rails-generate-errors-easily

Links
[1] https://uday.net/How-to-correct-rails-generate-errors-easily [2] https://uday.net/user/1 [3] https://uday.net/taxonomy/term/82