Creating a Model in Rails

Creating a Model in Rails

  1. In the terminal where your project folder is located, create a new model.     

 a. I’m creating a Users table  with a first_name, last_name, username, password, street, city and state. Password:digest coupled with the bcrypt gem is used to securely store the users password and allows for easy password authentication when completing forms.

b. Once the table is created, it’s time to rake db:migrate – This command will pull the model for use in your project.


    1. Let’s say you made a mistake with your table and want to replace, update or remove information or the whole table. 

a. It’s pretty simple with rails to alter your table – after creating a new rails g migration NameOfColumnToAdjust, just go to the migration file that’s created in your migrate —> db folder, create a new method using ‘def methodName’ then choose a command you wish to utilize, add in the name of the field, the data type and what you want it changed it. Finally add ‘end’ to your method to close.


b. Back in your terminal run rake db:migrate to merge the changes to your table.