{"id":6224,"date":"2018-12-28T07:47:02","date_gmt":"2018-12-28T07:47:02","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=6224"},"modified":"2018-12-28T23:08:05","modified_gmt":"2018-12-28T23:08:05","slug":"how-to-install-latest-ruby-on-rails-on-ubuntu-18-04-lts","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/28\/how-to-install-latest-ruby-on-rails-on-ubuntu-18-04-lts\/","title":{"rendered":"How to Install latest Ruby on Rails on Ubuntu 18.04 LTS"},"content":{"rendered":"<p>RoR or Ruby on Rails is an open source, cross-platform web development framework that provides a structure to the developers for their code. It helps them create applications and websites by abstracting and simplifying the repetitive tasks faced during development. It is called Ruby on Rails because Rails is written in the Ruby programming language, exactly how Symfony and Zend are written in PHP and Django in Python. Rails provide default structures for databases, web servers, and web pages. Famous applications like Soundcloud, Github and Airbnb are all based on Rails.<\/p>\n<p>Ruby on Rails is licensed under MIT and was first released in December 2005. All of its repositories are available on Github, including the latest release to date.<\/p>\n<p>This tutorial explains a step-by-step process for installing and configuring Ruby on Rails with all its prerequisites. Later, we will explain how to install and configure the PostgreSQL Database in order to create your first Rails project.The article also explains how to create a simple CRUD interface, making your application more interactive and useful.<\/p>\n<p>We have run the commands and procedures mentioned in this article on a Ubuntu 18.04 LTS system. We are using the Ubuntu command line, the Terminal, in order to install and configure Ruby on Rails. You can access the Terminal application either through the system Dash or the Ctrl+Alt+T shortcut.<\/p>\n<h2>Ruby on Rails Installation<\/h2>\n<p>In order to install Ruby on Rails, you first need to have the latest versions of some prerequisites installed and configured on your system, such as:<\/p>\n<ul>\n<li>RVM-Ruby Version Manager<\/li>\n<li>Ruby<\/li>\n<li>Nodejs-Javascript runtime<\/li>\n<li>Ruby Gems-Ruby Package Manager<\/li>\n<\/ul>\n<p>In this section, we will first have our system ready by first installing all these step-by-step, setting up their latest versions, and then finally install Ruby on Rails.<\/p>\n<h2>1. Install Ruby Version Manager (RVM)<\/h2>\n<p>The Ruby Version Manager helps us in managing Ruby installation and configuring multiple versions of Ruby on a single system. Follow these steps in order to install the RVM package through the installer script:<\/p>\n<h3>Step1: Add the RVM key to your system<\/h3>\n<p>Run the following command in order to add the RVM key; this key will be used when you install a stable version of RVM:<\/p>\n<p>$ gpg &#8211;keyserver hkp:\/\/keys.gnupg.net &#8211;recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3<br \/>\n7D2BAF1CF37B13E2069D6956105BD0E739499BDB<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Add the RVM key\" width=\"733\" height=\"231\" \/><\/p>\n<h3>Step2: Install Curl<\/h3>\n<p>We will be installing RVM through Curl. Since it does not come by default with the latest versions of Ubuntu, we will need to install it through the following commands as sudo:<\/p>\n<p>$ sudo apt install curl<\/p>\n<p>Please note that only authorized users can add\/remove and configure software on Ubuntu.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Install Curl\" width=\"686\" height=\"348\" \/><\/p>\n<p>The system will prompt you with a Y\/n option in order to confirm the installation. Please enter Y to continue, after which, Curl will be installed on your system.<\/p>\n<h3>Step3: Install the RVM Stable version<\/h3>\n<p>Now run the following command in order to install the latest stable version of RVM.<\/p>\n<p>$ curl -sSL https:\/\/get.rvm.io | bash -s stable &#8211;ruby<\/p>\n<p>This command will also automatically install all the required packages needed to install RVM.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Install packages for RVM\" width=\"733\" height=\"399\" \/><\/p>\n<p>The process will take some time depending on your Internet speed, after which RVM will be installed on your system.<\/p>\n<h3>Step4: Setup RVM source folder<\/h3>\n<p>Please note that the last few lines of the RVM installation output suggest running the following command:<\/p>\n<p>$ source \/usr\/local\/rvm\/scripts\/rvm<\/p>\n<p>This is used to set the source folder to the one mentioned in the output. You need to run this command in order to start using RVM.<\/p>\n<p>You might get the following output when setting up the source:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Setup RVM source folder\" width=\"561\" height=\"48\" \/><\/p>\n<p>In that case, run the following commands on your system:<\/p>\n<p>$ source ~\/.rvm\/scripts\/rvm<br \/>\n$ echo &#8220;source ~\/.rvm\/scripts\/rvm&#8221; &gt;&gt; ~\/.bashrc<br \/>\n$ source ~\/.bashrc<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Fix RVM not found issue\" width=\"580\" height=\"85\" \/><\/p>\n<p>Now the source for RVM is set. You can check the version number of RVM installed on your system through the following command:<\/p>\n<p>$ rvm &#8211;version<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Check RVM version\" width=\"728\" height=\"75\" \/><\/p>\n<p>This output also ensures that RVM is indeed installed on your system.<\/p>\n<h2>2. Configure Latest Version of Ruby as System Default<\/h2>\n<p>When you install RVM, the latest version of Ruby is also installed on your system. What you need to do, however, is to set up your system to use the latest version of Ruby as the system default. Follow these steps to do so:<\/p>\n<h3>Step1: Setup RVM latest stable version<\/h3>\n<p>First, we need to update the RVM on our system with the latest stable version available on https:\/\/get.rvm.io<\/p>\n<p>Run the following command to do so:<\/p>\n<p>$ rvm get stable &#8211;autolibs=enable<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Get latest stable RVM version\" width=\"665\" height=\"335\" \/><\/p>\n<h3>Step2: Get the list of all available Ruby versions<\/h3>\n<p>The following command gives you the list of all Ruby versions released till date:<\/p>\n<p>$ rvm list known<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Get a list of released Ruby versions\" width=\"708\" height=\"407\" \/><\/p>\n<p>Through this list, please choose the latest version of Ruby available. As you can see in the output, Ruby 2.6.0 is the latest version available.<\/p>\n<h3>Step3: Install the latest Ruby version<\/h3>\n<p>Now install the latest version of Ruby that you have selected in the previous step, by running the following rvm command:<\/p>\n<p>$ rvm install ruby-2.6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Install Ruby\" width=\"611\" height=\"416\" \/><\/p>\n<p>The process may take some time depending on your Internet speed, after which the selected number of Ruby will be installed on your system.<\/p>\n<h3>Step4: Set the latest version of Ruby as default<\/h3>\n<p>The following rvm command will help you in setting the latest installed version of Ruby as the system default:<\/p>\n<p>$ rvm &#8211;default use ruby-2.6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Set Ruby 2.6 as default version\" width=\"394\" height=\"95\" \/><\/p>\n<p>You can see that now my system will be using Ruby 2.6.0-rc1 as the default Ruby version.<\/p>\n<p>This can also be verified by running the following version command:<\/p>\n<p>$ ruby -v<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Check Ruby version\" width=\"516\" height=\"45\" \/><\/p>\n<h2>3. Install Nodejs and the gcc compiler<\/h2>\n<p>Before starting with the Rails development on Linux, we recommend using Nodejs as the Javascript runtime. It is a prerequisite for compiling Ruby on Rails asset pipeline.<\/p>\n<h3>Step1: Install the latest version of Nodejs<\/h3>\n<p>Use the following command in order to install the Nodesource repository to your system:<\/p>\n<p>$ curl -sL https:\/\/deb.nodesource.com\/setup_10.x | sudo -E bash &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Download Node.js\" width=\"704\" height=\"380\" \/><\/p>\n<p>Now install the latest version of Nodejs through the following apt command as sudo:<\/p>\n<p>$ sudo apt install -y nodejs<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Install Node.js\" width=\"536\" height=\"321\" \/><\/p>\n<p>The latest available version of Nodejs 10 will be installed on your system<\/p>\n<h3>Step2: Install the gcc compiler<\/h3>\n<p>The gcc compiler is another prerequisite that you need to install before performing any Rails development. Use the following command as sudo in order to install it:<\/p>\n<p>$ sudo apt install gcc g++ make<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Install gcc Compiler\" width=\"532\" height=\"201\" \/><\/p>\n<h2>4. Configure Latest Version of RubyGems as System Default<\/h2>\n<p>When you install RVM, RubyGems is also installed on your system. What we need to do, however, is to set up our system to use the latest version of RubyGems the system default. Ruby Gems is basically the Ruby on Rails package manager that comes with the command line tool-gem.<\/p>\n<p>Run the following gem command in order to update the system to use the latest version:<\/p>\n<p>$ gem update &#8211;system<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Update gem\" width=\"603\" height=\"275\" \/><\/p>\n<p>Now when you check the version number through the following command, you will see that your system is using the latest version of RubyGems in the command line:<\/p>\n<p>$ gem -v<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Check gem version\" width=\"212\" height=\"56\" \/><\/p>\n<h2>5. Install Ruby on Rails<\/h2>\n<p>Finally, after installing all the prerequisites, we can now install Ruby on Rails on our system by following these steps:<\/p>\n<h3>Step1: Look up for the latest available version<\/h3>\n<p>The RubyGems website maintains all the versions of Ruby on Rails till date, on the following link:<\/p>\n<p><a href=\"https:\/\/rubygems.org\/gems\/rails\/versions\">https:\/\/rubygems.org\/gems\/rails\/versions<\/a><\/p>\n<p>Choose the latest version of Ruby on Rails that you would like to install. At the time of writing this article, the latest available version is 5.2.2<\/p>\n<h3>Step2: Install the latest Ruby on Rails version<\/h3>\n<p>You can install the latest version of Ruby on Rails through the gem command line tool as follows:<\/p>\n<p>$ gem install rails -v 5.2.2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Install the latest Ruby on Rails version with gem\" width=\"438\" height=\"328\" \/><\/p>\n<p>The installation process might take some time depending on your Internet connection.<\/p>\n<p>After the installation is complete, run the following command to view the Rails version installed on your system.<\/p>\n<p>$ rails -v<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Check Rails version\" width=\"255\" height=\"55\" \/><\/p>\n<p>The command also verifies that Ruby on Rails is indeed installed on your system.<\/p>\n<h2>Rails Development<\/h2>\n<p>Ruby on Rails supports many databases such as SQLite, MySQL, and PostgreSQL. In this section, we will explain how to start with the Rails development with the PostgreSQL database. This will include:<\/p>\n<ul>\n<li>Installing PostgreSQL Database<\/li>\n<li>Configuring PostgreSQL and Creating Roles<\/li>\n<li>Your First Rails application<\/li>\n<li>Creating a simple CRUD with PostgreSQL database on Rails<\/li>\n<\/ul>\n<h2>1. Install and Setup PostgreSQL Database<\/h2>\n<h3>Step1: Install PostgreSQL<\/h3>\n<p>Use the following apt command as sudo in order to install the PostgreSQL database and some other required packages:<\/p>\n<p>$ sudo apt install postgresql postgresql-contrib libpq-dev -y<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Install PostgreSQL\" width=\"725\" height=\"355\" \/><\/p>\n<h3>Step2: Start and enable the PostgreSQL service<\/h3>\n<p>Once PostgreSQL is installed, you need to start the \u2018postgresql\u2019 service through the following command:<\/p>\n<p>$ systemctl start postgresql<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Start PostgreSQL\" width=\"632\" height=\"415\" \/><\/p>\n<p>The system will prompt you with an authentication dialog, as only an authorized user can enable services on Ubuntu. Enter the admin password and click the Authenticate button after which the service will start.<\/p>\n<p>The next step is to enable the service through the following command:<\/p>\n<p>$ systemctl enable postgresql<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Enable PostgreSQL\" width=\"616\" height=\"393\" \/><\/p>\n<p>The system will prompt you with a similar authentication dialog multiple times; enter the admin password each time and click the Authenticate button after which the service will be enabled.<\/p>\n<h3>Step3: Verify installation<\/h3>\n<p>$ Please run the following command in order to view a details stats report of your PostgreSQL installation:<\/p>\n<p>$ dpkg &#8211;status postgresql<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Check PostgreSQL Status\" width=\"586\" height=\"374\" \/><\/p>\n<h2>2. Configure PostgreSQL and Create Roles<\/h2>\n<p>PostgreSQL applications can be created by user or roles. By default, a \u201cpostgres\u201d user exists which is a superuser and it can create and migrate databases and also manage other user roles.<\/p>\n<p>Initially, you can log in as sudo on PostgreSQL through the following command:<\/p>\n<p>$ sudo -u postgres psql<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Use su to become postgres user\" width=\"408\" height=\"156\" \/><\/p>\n<p>Here you can change the password of postgres as follows:<\/p>\n<p>postgress=# password postgres<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Change postgres password\" width=\"313\" height=\"80\" \/><\/p>\n<h3>Create a Role<\/h3>\n<p>A superuser can create a new user role through the following command:<\/p>\n<p><em>$ create role \u201crole_name\u201d with <\/em>createdb<em> login password \u201c\u2018password\u2019\u201d\u2019 ;<\/em><\/p>\n<p>Example:<\/p>\n<p>postgress=# create role dev_rails with createdb login password &#8216;rockon123&#8217; ;<\/p>\n<p>We are creating a role by the name of \u201cdev_rails\u201d. This is a user that will create a db for our first Rails application.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Create posgres role\" width=\"701\" height=\"72\" \/><\/p>\n<p>A superuser can view the list of roles existing on PostgreSQL as follows:<\/p>\n<p>postgress=# du<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"List roles in PostgreSQL\" width=\"821\" height=\"186\" \/><\/p>\n<p>Use <em>Ctrl+z<\/em> to exit PostgreSQL.<\/p>\n<h2>3. Your First Rails application<\/h2>\n<p>Now we will create our first Rails application with PostgreSQL as the default database. This involves the following steps:<\/p>\n<h3>Step1: Create a new Rails application<\/h3>\n<p>Create a new project by the name of \u201cfirstapp\u201d, or any other name, through the following command and specify PostgreSQL as the database:<\/p>\n<p>$ rails new firstapp -d postgresql<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Create a new Ruby on Rails Application\" width=\"577\" height=\"354\" \/><\/p>\n<p>This will create a project folder in your home folder as follows:<\/p>\n<p>$ ls<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Rails app creates, verify with ls command\" width=\"602\" height=\"113\" \/><\/p>\n<h3>Step2: Configure your Rails project to incorporate the PostgreSQL user role<\/h3>\n<p>Now we want the user role we created in PostgreSQL to be able to create a database in the Rails application. For this, you need to edit the database.yml file located in your newly created application\u2019s folder in the \/config\/ folder.<\/p>\n<p>Move to your first application and then the config folder as follows:<\/p>\n<p>$ cd \/firstapp\/config<\/p>\n<p>Here you will see the database.yml file. You can edit this file through your favorite text editor. We will be doing so through the Nano editor by using the following command:<\/p>\n<p>$ nano database.yml<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Change database settings\" width=\"706\" height=\"111\" \/><\/p>\n<p>In this file, you will be able to see mainly three sections:<\/p>\n<ul>\n<li>Development<\/li>\n<li>Test<\/li>\n<li>Production<\/li>\n<\/ul>\n<p>We will need to configure the Development and Test sections of the file.<\/p>\n<p>Make the following configurations in the Development section<\/p>\n<table>\n<tbody>\n<tr>\n<td>database: firstapp_development<\/p>\n<p>username: dev_rails<\/p>\n<p>password: rockon123<\/p>\n<p>host: localhost<\/p>\n<p>port: 5432<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Database configuration\" width=\"449\" height=\"229\" \/><\/p>\n<p>And, the following in the Test section:<\/p>\n<table>\n<tbody>\n<tr>\n<td>database: firstapp_test<\/p>\n<p>username: dev_rails<\/p>\n<p>password: rockon123<\/p>\n<p>host: localhost<\/p>\n<p>port: 5432<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Note: Please make sure that the syntax is correct. Each line should be preceded by 2 spaces and NOT tabs.<\/p>\n<p>Save the file by pressing Ctrl+X, then Y and then by hitting Enter.<\/p>\n<h3>Step3: Generate and then migrate the Database<\/h3>\n<p>Generate the database through the following rails command:<\/p>\n<p>$ rails db:setup<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Generate the database\" width=\"726\" height=\"143\" \/><\/p>\n<p>Please make sure that there are no errors. Most errors are due to the wrong syntax in the database.yml file or the inconsistency in the username and password from the one you created in PostgreSQL.<\/p>\n<p>After the successful generation, migrate the database through the following rails command:<\/p>\n<p>$ rails db:migrate<\/p>\n<p><img decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" \/><\/p>\n<h3>Step4: Start the Puma Rails web server<\/h3>\n<p>After completing the application setup, please enter the following command in order to start the default Puma web server:<\/p>\n<p>$ rails s -b localhost -p 8080<\/p>\n<p>Or in our case,<\/p>\n<p>$ rails s -b 127.0.0.1 -p 8080<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Start Rails web server\" width=\"587\" height=\"186\" \/><\/p>\n<p>After this command, your first Rails application is running on the local host at port 8080.<\/p>\n<h3>Step5: Open the default Rails Project Homepage<\/h3>\n<p>You can view your database successfully being hosted on the default Rails Project homepage by entering this URL in one of your web browsers:<\/p>\n<p><em>http:\/\/localhost:8080\/<\/em><\/p>\n<p>You can also use your localhost IP, like us, in the above-mentioned URL:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Rails default homepage\" width=\"750\" height=\"425\" \/><\/p>\n<p>You can not perform any CRUD operation on this simple application. Follow the article some more in order to make your application a little more interactive.<\/p>\n<h2>4. Create a simple CRUD with PostgreSQL database on Rails<\/h2>\n<p>Let us make our application more interactive by implementing a CRUD(Create, Read, Update, Delete) interface.<\/p>\n<h3>Step1: Create a Scaffold in Rails<\/h3>\n<p>Run the following command in order to create a scaffold in your Rails application folder<\/p>\n<p>$ rails g scaffold Post title:string body:text<\/p>\n<p>Then migrate the database by running the following command:<\/p>\n<p>$ rake db:migrate<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Create a simple CRUD with PostgreSQL database on Rails\" width=\"631\" height=\"668\" \/><\/p>\n<h3>Step2: Run the application on Puma Rails Web Server<\/h3>\n<p>Next, run your application on the localhost by running the Puma web server again through the following command:<\/p>\n<p>$ rails s -b localhost -p 8080<\/p>\n<p>You can also use your localhost IP, like us, for the above-mentioned command:<\/p>\n<p>$ rails s -b 127.0.0.1 -p 8080<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Run own application on Rails webserver\" width=\"529\" height=\"181\" \/><\/p>\n<h3>Step3: Open the \u2018Posts\u2019 page in Rails Project<\/h3>\n<p>You can view your database successfully being hosted on the Rails Project page by entering the URL in one of your web browsers:<\/p>\n<p><em>http:\/\/localhost:8080\/posts\/<\/em><\/p>\n<p>Or use a localhost IP like us:<\/p>\n<p><em>http:\/\/127.0.0.1:8080\/posts<\/em><\/p>\n<p>You will be able to see a simple CRUD interface through which you can create, edit, show and destroy posts.<\/p>\n<p>When I created a post using the New Post link, here is how my posts page looked like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/vitux.com\/wp-content\/plugins\/a3-lazy-load\/assets\/images\/lazy_placeholder.gif\" alt=\"Test Posts app\" width=\"456\" height=\"243\" \/><\/p>\n<p>You have now successfully completed the entire process of installing Ruby on Rails on your Ubuntu and then creating a sample application using the PostgreSQL database. This will serve as a basis for you to develop more productive and interactive database applications through Ruby on Rails.<\/p>\n<p><a href=\"http:\/\/lxer.com\/module\/newswire\/ext_link.php?rid=264331\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>RoR or Ruby on Rails is an open source, cross-platform web development framework that provides a structure to the developers for their code. It helps them create applications and websites by abstracting and simplifying the repetitive tasks faced during development. It is called Ruby on Rails because Rails is written in the Ruby programming language, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/28\/how-to-install-latest-ruby-on-rails-on-ubuntu-18-04-lts\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Install latest Ruby on Rails on Ubuntu 18.04 LTS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6224","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=6224"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6224\/revisions"}],"predecessor-version":[{"id":6843,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6224\/revisions\/6843"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=6224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=6224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=6224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}