CREATING A SIMPLE BLOG USING RAILS

Kingsley Izundu
5 min readMar 22, 2018

REQUIREMENTS:

WINDOWS

RAILS 4.2 OR 5.1

START:

Hello everybody, today we shall be creating a simple blog using rails framework. The rails framework is a web framework or a gem for the ruby programming language that allows us to build websites as fast as possible. However, people are usually turned off because of the complexity of setting up rails to work on windows. In this tutorial, we shall be as clear and simple so that you can follow through with ease.

We shall assume you don’t have ruby on rails installed: so follow this tutorial from the beginning to get it in debt.

Install ruby from : https://rubyinstaller.org/downloads/

Make sure you select the one which corresponds with your system i.e 32(x86) or 64(x64) bit. In this tutorial, we have selected ruby 2.4.3–2(x64)

Now run and install ruby in non-space path: i.e c:/users/ruby but not c:/users/program files/ruby

Note: Ruby usually have issues with space separated path names on windows especially.

While installing, make sure that you add to environment variable so that it can recognize the ruby command.

When you are done installing ruby, install the dev kit from the same link above. (make sure that the path is non-spaced)

Now cd to the devkit directory and type ruby dk.rb init

Then type: ruby dk.rb install

Now install rails by typing : gem install rails –version 5.0.0

Some libraries rails depend on require JavaScript runtime to be installed; now we have to install Node.js so those libraries work properly.

Download Node.js installer

Run the node-v4.4.7.pkg installer

Restart your computer when done; so rails can access Node.js

When restart: go to start menu and click the ‘start command prompt with ruby’

To see that you have rails installed now, type rails –v to see the version of rails.

Because we shall be introducing a little of git hub; we advise you create a repository on bitbucket, and copy the HTTPS repository here; Bitbucket is the VCS we shall be using for our project.

When done;

Still on your ruby command window; cd to the path you will like to clone your repository; (make sure it is non-spaced)

Then type — ‘git clone [paste the HTTPS of your repository here]

Cd to the local repo right now and then type — ‘rails new .’ (rails new dot)

This will install all the rails dependency and create a new app with the name of the repository you created on bitbucket.

Now, we shall proceed to install the lines-engine. The lines engine is the gem we will be using to create our blog. Gems are like libraries to keeps us from DRY coding and promotes reusability in the open source environment

Open up sublime or any text editor of your choice and locate the gem file by using CTRL P ; type Gemfile and hit enter;

Then add gem ‘lines-engine’ as part of the gem file.

And then run bundle

This will install all the gems for the app

Type: rails –g lines:install this will install the lines engine gem

It will ask you if you would like to create new user, you should respond ‘yes’

Now you might notice that it breaks because of an error such as; — “please specify the rails release…”

We shall correct the error by going into the codes and changing the version of rails used.

Now open up your text editor i.e sublime text and click on app; click on db and locate migrate;

Now append ‘[4.2]’ without the single quote; do this to every migration class.

When done, try to use the command again rails –g lines:install

You will be prompted to enter your name, email address and password.

Confirm the information and then the rails-engine tries to set up your application for blogging.

Now another error might arise at this stage: the bcrypt_ext error:

We will solve this in a minute:

Add gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', require: 'bcrypt' if Gem.win_platform? To your gemfile and then run bundle install; to install bcrypt.

When done; run the rails –g lines:install again

You should now have the user created. (Note your email and password) because we shall be using it to login to the admin portal to add new articles

Now locate the config file and locate; lines-config.yml and adjust the settings as you desire;

When done with configuration; run rake db: migrate--- what this does is to actually create the database or backend for the schema which you already have.

Now type: rails s or rails server

Then launch your blog by going to localhost:3000/blog

You might encounter an error about some

Error encountered after launching localhost:3000/blog

variable $max_width as undefined, we would correct that by adding it across all the class which requires it:

Locate app/assets/stylesheet/lines and on the following files, add @import 'variables_and_mixins'; at the top most to be the first code you see.

Article.scss

Footer.scss

General.scss

Messages.scss

Navbar.scss

Pagination.scss

Now, refresh your browser and it should be fine.

You can further make some adjustments on your lines-config.yml.

To see all routes which you can visit enter rake routes; this will display all routes.

Visit localhost:3000/blog/admin

Login with your email and password to begin managing the blog.

first launch after publishing an article

You can also click on the horizontal line menu above to explore formatting tips such as adding image to blog contents etc.

Thank you

Enjoy Ruby on Rails

--

--