DEV Community

Sheridan
Sheridan

Posted on • Edited on

Creating an Application| Ruby on Rails

Hello again! This blog is all about the basics of starting a Ruby on Rails backend to communicate to a React frontend. For our purposes we will build a todo list. The most basics portions of a Rails app is the route, controllers, model, and of course using all of that to migrate the data. Let's get started!

To begin, you want to create your Rails app. Simply open a terminal and cd into the directory where you want to create the rails app. Type in the following code and viola, a new app is created.
rails new name of your app
It should look something like this: Image descriptionMy app being called example app. Once you have created the app cd into it and we can start building the basics.
cd example-app

Ok, now that it's created it we want to take a look around.

Let's start by adding a route to our routes file, config/routes.rb.
Image description This is what mine would look like. This code would display all the todos that I have.

Next we want to create a controller
Image description
Image descriptionI went ahead and put this code in for the most basic functionality.

Now that we have a controller and a route let's create the next piece, the model.

A model is what Ruby uses to represent data. To create a model, let's use the model generator
Image descriptionThis will create the most basic structure for the todo table - a title in the form of a string, and a body in the form of text.

This will create a models/todo.rb file. In there I wrote some basic code to get the app working.Image description

Whew, we are almost there!

The last thing needed to create the most basic application is to migrate Image descriptionSimply run rails db:migrate in the terminal. The four lines below are to show that the migration is successful.

To make sure that your application was created successfully you can run rails s A.K.A. rails server the browser should return something like thisImage description The array is empty because we created an application but did not put any information into the database yet.

Congratulations! You have officially created a basic Ruby on Rails App!

Top comments (0)