Member-only story
Getting Started With Rails Part 2
As mentioned in part 1 we now need to complete the code in order to make a new article. At this point, we need to make an article model and add a create action in order to add the article to our database. First I would, however, add a testing framework and follow the TDD principles, I made a guide for RSpec Rails here.
In order to create the database model, I ran the following command
$ rails generate model Article title:string text:text
Why is the title a string and the body text? String translates to “Varchar” in your database, while text translates to “text”. Varchar values contain small chunks of data (for example a title) and text can be of almost any length.
This is an amazing feature of rails being it will automatically map out our database for us. If you navigate to the db/migrate we can see what Rails has done, as you can see it has created a method called change, it contains articles (plural, we can place article objects inside) with the two fields of an article (our title string and text article text).

Follow this we run the command $ rails db:migrate this command runs this change method and modifies the database accordingly. Like magic we now have a schema file with all of our changes applied, now all we need to do is to make a create action in order to pass the fields to…