What is Ruby on Rails
Ruby on Rails is the most popular server-side web application framework that is written in Ruby (open-source programming language).
You’ve probably already used many of the applications that were built with Ruby on Rails, some of those big names are: Hulu, Instacart, Basecamp, GitHub, Shopify, Airbnb, Zendesk, Square, Crunchbase, but there are hundreds of thousands of applications built with the framework since it was released in 2004.
Ruby on Rails is open-source software, and it's free to use.
Installing Rails
To install Rails, use the gem install command provided by RubyGems:
gem install rails
You can verify that everything is installed correctly, by running the following:
rails --version
For example, I get "Rails 6.0.3.4". We are ready to continue.
my_app Example
Open up a command line or terminal. To generate a new rails application, use rails new command followed by the name of your application:
rails new my_app
To switch to my_app's directory, we use the cd command, which stands for change directory.
cd my_app
The my_app directory has auto-generated files and folders, that's the structure of a Rails application. All those files and folders are created by default:
Rails application logic is organized into 3 major layers: Model-View-Controller. The Model is where the "business logic" lives. The Controller routes the commands to the model. The View renders HTML or JSON templates as a view.
The model is chiefly handled by Active Record (with some backup from Active Model). That's the framework for talking to the database.
The controller is handled by Action Controller and the view by Action View, together presented as Action Pack.
In addition to these core frameworks, we also ship with Action Mailer, for sending HTML and plaintext emails.
Starting up the Web Server
Creating the database
Before we startup the rails server, we need to create the database by running:
rails db:create
We have a functional Rails application already. To see it, we just need to start a web server on our development machine by running the following:
rails s
This will fire up Puma, a web server distributed with Rails by default. Open a browser window and navigate to http://localhost:3000 the Rails default information page looks like this:
Ruby on Rails my_app is up and running.
To connect with me please check my Github, LinkedIn or Twitter.
Thanks for reading!
Top comments (0)