rails-generate: add migration (#3975)

client-spec/clarity
Nelson Figueroa 2020-04-15 09:29:07 -07:00 committed by GitHub
parent 5599de1063
commit ec911e0308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -1,19 +1,24 @@
# rails generate
> Generate new Rails templates in an existing project.
> More information: <https://guides.rubyonrails.org/command_line.html#rails-generate>.
- List all available generators:
`rails generate`
- Generate a new model:
- Generate a new model named Post with attributes title and body:
`rails generate model {{model_name}}`
`rails generate model {{Post}} {{title:string}} {{body:text}}`
- Generate a new controller:
- Generate a new controller named Posts with actions index, show, new and create:
`rails generate controller {{controller_name}}`
`rails generate controller {{Posts}} {{index}} {{show}} {{new}} {{create}}`
- Generate a scaffold for a new model:
- Generate a new migration that adds a category attribute to an existing model called Post:
`rails generate scaffold {{model_name}}`
`rails generate migration {{AddCategoryToPost}} {{category:string}}`
- Generate a scaffold for a model named Post, predefining the attributes title and body:
`rails generate scaffold {{Post}} {{title:string}} {{body:text}}`