Ruby on Rails is being used for some of most of relevant companies in the world, such as Git Hub, AirBnb, Groupon, Hulu, etc. In addition, there is a high demand for Ruby on Rails on the labor market for web back-ending development. However, there are some languages in the market where you must take into account, before considering to use Ruby in your project.
Here are some Advantages and Disadvantages of developing on Ruby on Rails :
Uses MVC(model-view-controller) philosophy, in order to separate the application in models, which is easier for developers to add new features and maintenance
You don’t need to code all your applications from scratch. You can use RubyGems to install some feature on your website that was already developed before.
Language and Gems are well documented online.
Lower performance, mainly, because of use of a great amount of gems.
Less popular than Java and PHP, therefore, there are fewer developers than these languages.
This post will show how you prepare your machine to start developing using Ruby on Rails.
Before we start to prepare a development environment for Ruby on Rails, there are a few concepts that we should know :
Ruby - Created by Yukihiro Matsumoto, Ruby is the programming language used to code. Ruby is a language used for general purposes, not only for web development.
Ruby on Rails - is a web application development framework written in the Ruby language. It is designed to make programming web applications easier by making assumptions about what every developer needs to get started.
Gem (RubyGems) - is the package manager for the Ruby programing language that provides lots of libraries to your Ruby project. Before you start, it is recommended to check the RubyGems website, to check if the features you want to use on your project is already available.
IRB (Interactive Ruby Shell) - is the command line interface with Ruby, which allows interaction with code, when it is running.
How to install Ruby on Windows and Mac
There are a few differences on installing Ruby on Windows and Mac PCs. MacOs after version 10.12 already have Ruby installed, so you will just need to check the version of Ruby on this machine.
Step 1 - Install RubyInstaller (Windows only)
If you don’t have the Ruby installed on your machine, you should download the RubyInstaller from the site https://rubyinstaller.org/ . This also will get the RubyGems along to this package, which will allow installing the web-framework Rails.
After installation, check on the CMD if Ruby is installed by using the command: ruby -v
*Some Ruby Installer will include the MSYS2, which a Unix-like environment, a command-line interface for those who are used to Unix Shell Script commands. The installation of this component is optional.
Step 2 - Install Rails (Windows/Mac)
Go to the CMD(for Windows) or Terminal(for Mac) and use the command: gem install rails
After installation, check on the CMD(for Windows) or Terminal(for Mac) if Rails is installed by using the command: rails -v
*Puma WebServer is built-in with the installation of Rails.
Step 3 - Install MySQL and MySQL gem (Windows/Mac)
You will need to configure MySQL on your environment if you to work with a database. Go to https://dev.mysql.com/downloads/mysql/ and configure MySQL server.
After installation, go to the CMD(for Windows) or Terminal(for Mac) and use the command: gem install mysql2
Step 4 - Choose a text editor (Windows/Mac)
You can use any text editor to code with Ruby. However, I suggest using one colored text editor, in order to make easy to code and identify the elements of Ruby programming language. Here a few suggestion of text editors:
Step 5 - Create a new project (Windows/Mac)
On the CMD(for Windows) or Terminal(for Mac), choose the folder you want to create a project. After that, use the following command: rails new
Now you have a folder with your project created.
Step 6 - Create the database (Windows/Mac)
With the installation of MySQL, there is a command-line called “MySQL XX Command Line Client” that we can use to connect to the database server. Connect to MySQL and create the database
by using the following command :
Then, grant access to your rails application by using the following command :
GRANT ALL PRIVILEGES ON
Finally, enter on your text-editor and configure the file database.yml in the config folder. Include in the file the information of the database, user and password passed to MySQL.
To test if your project is connecting to the database go to the CMD(for Windows) or Terminal(for Mac), and use the following command: rails db:schema:dump.
This will create a new file called schema.rb in the db folder.
Step 7 - Launch the project
On the CMD(for Windows) or Terminal(for Mac), go to your project folder and use the command: rails server
Go to the browser and check if the website is online. On my machine, the address is http://localhost:3000
Congratulations!!! You launched your first Ruby Application!!!