Thursday, December 1, 2022

Building a Rails Blog App

 Rails comes with a number of scripts, called generators, designed to make a developer's life easier by creating everything they need to get started on a particular task. One of them is the new application generator, which provides you with the foundation of a Rails application so you don't have to write it yourself.


To use this generator, open a terminal, navigate to a folder where you have permission to create files, and run:


$ rails new blog

This will create a Rails app called Blog in the blog directory and install the gems whose dependencies are mentioned in the Gemfile when using bundle install.


You can see all the possible command line options that the Rails app generator accepts by running rails new --help.


Once you've created the blog app, navigate to its folder:


$ cd blog

The blog directory will contain several auto-generated files and folders that define the structure of the Rails application. Most of the work in this tutorial will take place in the app folder, but for now, let's go over the functions of each folder that Rails creates in the new default application:

Installing Rails


Before installing Rails, you need to make sure that you have the required prerequisites installed on your system. These include:


ruby

SQLite3

Installing Ruby

Open command line applications. On macOS, open Terminal.app; on Windows select "Run" from the Start menu and write cmd.exe. Any commands that begin with a dollar sign $ must be run on the command line. Make sure you have the current version of Ruby installed:


$ ruby ​​--version

ruby 2.7.0

Rails requires Ruby version 2.7.0 or later to be installed. It is preferable to use the latest version of Ruby. If the version number is less than this (such as 2.3.7 or 1.8.7), you will need to install a fresh copy of Ruby.


To install Ruby on Windows, you first need to install the Ruby Installer.


Additional installation methods for most operating systems can be seen

Building a Rails Blog App

 Rails comes with a number of scripts, called generators, designed to make a developer's life easier by creating everything they need to...