Getting started with Ruby on Rails: A blog app (Part 1)

Brian Ngeywo
2 min readDec 2, 2020
Photo by Safar Safarov on Unsplash

Getting started with a new language can sometimes be hard, especially if you don’t have a programming background. Luckily, Ruby on rails is one of the most beginner friendly frameworks to learn in 2020. The main goal of the framework is to get the programmer to be as productive by reducing the amount of decisions to made.

In this tutorial, I will be creating a simple blog app that allows users to post new articles. As for the front-end, I will be using a CSS framework called Tailwind.

So, let’s get to work!

Here is my environment

Ruby 2.7.2
Rails 6.0.3.4

1. Create a new rails app.

rails new blog-app
cd blog-app
code .

This command will create a new ruby on rails app with the name blog-app. make sure you have internet access before creating a new rails app. After it’s done, go into the blog-app folder and open your favorite code editor, I’ll be using VSCode.

STEP 2: Setup Tailwindcss

From your terminal inside your folder, paste this command.

yarn add tailwindcss

Go toapp/javascript/css/application.scss file.
If there is no application.scss in your path, create it.

import tailwindcss files to the application.scss file.

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

require the application.scss file in your javascript file: app/javascript/packs/application.js

require("css/application")

open file: postcss.config.js which is at the root of your application, and add this line.

require('tailwindcss'),

now go to your application layout page add this line in the head, just before the javascript _pack_tag. In my case it was file: app/views/layouts/application.html.erb

<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>

We are now ready to build our app.

3. Let’s create the articles!

Create the articles with the scaffold command. you can learn more about the scaffold command here.

rails g scaffold article title:string body:string

here we are creating articles with a title and a body.

lets run our database migrations!

rake db:migrate

now in our app/config/routes.rb

Add this line

root to: 'articles#index'

Now boot the server.

rails s

That’s all for today. i’ll continue with our app on my next article.

Happy holidays!

--

--