| Start | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Rails Generate Model To generate an 'NAME' is the name of the model. 'field' is the name of the column in the DB table and 'type' is the column type (e.g. To setup foreign keys, add So say you wanted to setup a
|
||||||||||||||||||||||||||||||||||||||||||
| Rails Generate Migration You can generate a rails migration file from the terminal using the following command: For a list of all the options supported by the command, you could run the command without any arguments as in For example, if you want to add Rails will create the following migration file: Now, apply the pending migrations to the database by running the following in the terminal: Note: For even less typing, you can replace |
||||||||||||||||||||||||||||||||||||||||||
| Rails Generate Scaffold DISCLAIMER: Scaffolding is not recommended unless it's for very conventional CRUD apps/testing. This may generate a lot of files(views/models/controllers) that are not needed in your web application thus causing headaches(bad ????). To generate a fully working scaffold for a new object, including model, controller, views, assets, and tests, use the Then you can run Then you can visit http://localhost:3000/widgets (opens new window) and you'll see a fully functional CRUD scaffold. |
||||||||||||||||||||||||||||||||||||||||||
| Rails Generate Controller we can create a new controller with The controller generator is expecting parameters in the form of The following creates a Greetings controller with an action of hello. You will see the following output This generates the following
It will also add routes for each action in Parameters
RemarksThe possible values for 'type' in
|
Read Article
https://develop.horje.com/learn/1434/reference