What Is Ruby on Rails?

Image credits: RubyonRails.org

A Web Development Framework for Purists

Back in 1995, Yukihiro Matsumoto released Ruby 0.95 as a pure, object-oriented (OO), general-purpose programming language:

As a language maniac and OO fan for 15 years, I really wanted a genuine object-oriented, easy-to-use scripting language. I looked for but couldn’t find one. So I decided to make it. — Y. Matsumoto

Then in 2004, David Heinemeier Hansson released the first version of Ruby on Rails as a web application framework which he used to launch his team management application Basecamp. He open sourced Ruby on Rails in 2005, and Apple released it with OS X Leopard in 2007.

For this tutorial, I’ll refer to Ruby on Rails as Rails for short; some people also use RoR.

Rails is used by a wide variety of popular web applications you may know, such as GitHub, Shopify, Airbnb, Twitch, SoundCloud, Hulu, Zendesk, Square, and Highrise. However, it’s been criticized for scalability limitations, most notably with Twitter, which gradually had to move many of its services to other platforms. That said, Twitter has high transaction rates and scalability challenges.

What is Ruby on Rails Sample Rails Apps with Juggler for fun

In this tutorial, I’ll answer the question “What is Ruby on Rails?” and introduce you to the basics of the programming framework to help you experiment with it.

Before we get started, please remember, I participate in the discussions below. If you have a question or topic suggestion, please post a comment below or contact me on Twitter @reifman. 

What Is Ruby on Rails?

Ruby on Rails is a popular, open-source, object-oriented web development framework used by many programmers and application providers. It’s also based on a model view controller (MVC) approach.

Models map to the databases and functionality to an object in the application, such as users. Rails provides a standard convention for naming and file directory structures, which simplifies programming but also provides for automated solutions to building functionality, called scaffolding. It also ensures a common environment for developers to work together and benefit from each other’s efforts.

Optimizing for programmer happiness with Convention over Configuration is how we roll.

The Controller manages requests primarily between the user and the server, gathering data from models and returning it to the user through View files.

Views are essentially programmatic HTML files that lay out the page with the dynamic data.

Rails conventions guide developers to rely on RESTful routing. Controller actions generally e.g. new, create, edit, update, destroy, show, index, etc. These are what allow for users and the system to interact with various features

Collectively, the MVC features of Rails are called the Action Pack, i.e. ActionController, ActionView and ActiveRecord, the latter for interacting with the database.

What is Ruby on Rails The Action Pack View Controller Record

Rails’ founder Hansson provides a principled theology behind the framework called The Ruby on Rails Doctrine.

What is Ruby on Rails The Rails Doctrine

The Ruby on Rails Doctrine

The Rails doctrine consists of eight tenets:

  1. Optimize for programmer happiness: whenever possible, Ruby attempts to meet the desires of the programmer.
  2. Convention over Configuration: choosing standard, platform-wide default choices makes it faster and easier for programmers to get started on new projects.
  3. The menu is omakase: the team behind Ruby on Rails has selected the best tools and approaches, and everyone will be happier using them.
  4. No one paradigm: in the end Rails embraces flexible solutions for various occasions.
  5. Exalt beautiful code: a primary focus on aesthetics and simplicity.
  6. Value integrated systems: an orientation towards complete awareness and cohesion of all the tools needed to build applications and solutions.
  7. Progress over stability: a willingness to take risks to move the platform forward.
  8. Push up a big tent: welcoming a big community of participants and their voices to set the vision.

The chief accomplishment of Rails was to unite and cultivate a strong tribe around a wide set of heretical thoughts about the nature of programming and programmers. — David Heinemeier Hansson

Here are the primary Rails contributors currently (founder David Hansson is in the upper left):

What is Ruby on Rails The Core Team

And they do have a warm, welcoming community:

  • The Ruby on Rails: Talk mailing list
  • The Ruby on Rails StackOverflow Q&A tag
  • The #rubyonrails IRC channel on irc.freenode.net
  • An annual RailsConf conference for real world meetups

Perhaps you’re interested in diving in further, so here’s how to get started.

Getting Started With Ruby on Rails

Rails has a collection of outstanding documentation. Here’s a peek at the Getting Started Guide:

What is Ruby on Rails Getting Started

The guide steps you through a general introduction, basic installation and some beginner Rails programming.

Installing Ruby on Rails

Mac users will find Ruby pre-installed. Windows users can check out RailsInstaller. For a full Rails installation on OS X, the guide recommends Tokaido. Alternatively, Daniel Kehoe suggests avoiding one-click installers and provides detailed instructions for Mac OS X El Capitan install.

Experienced Rails developers also report that it makes web application development more fun. — Rails Guide

However, it had been a while since I’d run Rails, and reinstalling it on my late model Mac on El Capitan was time-consuming.

Verify the Installation of Ruby

On OS X, Ruby will be pre-installed:

$ ruby -v
ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]

Install the Rails Framework

My Rails installation took about 10 to 15 minutes (be patient):

$ sudo gem install rails
Fetching: thread_safe-0.3.5.gem (100%)
Successfully installed thread_safe-0.3.5
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: minitest-5.8.4.gem (100%)
Successfully installed minitest-5.8.4
Fetching: activesupport- (100%)
Successfully installed activesupport-
Fetching: rack-1.6.4.gem (100%)
Successfully installed rack-1.6.4
Fetching: rack-test-0.6.3.gem (100%)
Successfully installed rack-test-0.6.3
Fetching: mini_portile2-2.0.0.gem (100%)
Successfully installed mini_portile2-2.0.0
Fetching: nokogiri- (100%)
Building native extensions.  This could take a while...
Successfully installed nokogiri-
Fetching: loofah-2.0.3.gem (100%)
Successfully installed loofah-2.0.3
Fetching: rails-html-sanitizer-1.0.3.gem (100%)
Successfully installed rails-html-sanitizer-1.0.3
Fetching: rails-deprecated_sanitizer-1.0.3.gem (100%)
Successfully installed rails-deprecated_sanitizer-1.0.3
Fetching: rails-dom-testing-1.0.7.gem (100%)
Successfully installed rails-dom-testing-1.0.7
Fetching: builder-3.2.2.gem (100%)
Successfully installed builder-3.2.2
Fetching: erubis-2.7.0.gem (100%)
Successfully installed erubis-2.7.0
Fetching: actionview- (100%)
Successfully installed actionview-
Fetching: actionpack- (100%)
Successfully installed actionpack-
Fetching: activemodel- (100%)
Successfully installed activemodel-
Fetching: arel-6.0.3.gem (100%)
Successfully installed arel-6.0.3
Fetching: activerecord- (100%)
Successfully installed activerecord-
Fetching: globalid-0.3.6.gem (100%)
Successfully installed globalid-0.3.6
Fetching: activejob- (100%)
Successfully installed activejob-
Fetching: mime-types-2.99.gem (100%)
Successfully installed mime-types-2.99
Fetching: mail-2.6.3.gem (100%)
Successfully installed mail-2.6.3
Fetching: actionmailer- (100%)
Successfully installed actionmailer-
Fetching: thor-0.19.1.gem (100%)
Successfully installed thor-0.19.1
Fetching: railties- (100%)
Successfully installed railties-
Fetching: bundler-1.11.2.gem (100%)
Successfully installed bundler-1.11.2
Fetching: concurrent-ruby-1.0.0.gem (100%)
Successfully installed concurrent-ruby-1.0.0
Fetching: sprockets-3.5.2.gem (100%)
Successfully installed sprockets-3.5.2
Fetching: sprockets-rails-3.0.1.gem (100%)
Successfully installed sprockets-rails-3.0.1
Fetching: rails- (100%)
Successfully installed rails-
Parsing documentation for thread_safe-0.3.5
Installing ri documentation for thread_safe-0.3.5
Parsing documentation for tzinfo-1.2.2
Installing ri documentation for tzinfo-1.2.2
Parsing documentation for minitest-5.8.4
Installing ri documentation for minitest-5.8.4
Parsing documentation for activesupport-
unable to convert "\x84" from ASCII-8BIT to UTF-8 for lib/active_support/values/unicode_tables.dat, skipping
Installing ri documentation for activesupport-
Parsing documentation for rack-1.6.4
Installing ri documentation for rack-1.6.4
Parsing documentation for rack-test-0.6.3
Installing ri documentation for rack-test-0.6.3
Parsing documentation for mini_portile2-2.0.0
Installing ri documentation for mini_portile2-2.0.0
Parsing documentation for nokogiri-
unable to convert "\xCA" from ASCII-8BIT to UTF-8 for lib/nokogiri/nokogiri.bundle, skipping
Installing ri documentation for nokogiri-
Parsing documentation for loofah-2.0.3
Installing ri documentation for loofah-2.0.3
Parsing documentation for rails-html-sanitizer-1.0.3
Installing ri documentation for rails-html-sanitizer-1.0.3
Parsing documentation for rails-deprecated_sanitizer-1.0.3
Installing ri documentation for rails-deprecated_sanitizer-1.0.3
Parsing documentation for rails-dom-testing-1.0.7
Installing ri documentation for rails-dom-testing-1.0.7
Parsing documentation for builder-3.2.2
Installing ri documentation for builder-3.2.2
Parsing documentation for erubis-2.7.0
Installing ri documentation for erubis-2.7.0
Parsing documentation for actionview-
Installing ri documentation for actionview-
Parsing documentation for actionpack-
Installing ri documentation for actionpack-
Parsing documentation for activemodel-
Installing ri documentation for activemodel-
Parsing documentation for arel-6.0.3
Installing ri documentation for arel-6.0.3
Parsing documentation for activerecord-
Installing ri documentation for activerecord-
Parsing documentation for globalid-0.3.6
Installing ri documentation for globalid-0.3.6
Parsing documentation for activejob-
Installing ri documentation for activejob-
Parsing documentation for mime-types-2.99
Installing ri documentation for mime-types-2.99
Parsing documentation for mail-2.6.3
Installing ri documentation for mail-2.6.3
Parsing documentation for actionmailer-
Installing ri documentation for actionmailer-
Parsing documentation for thor-0.19.1
Installing ri documentation for thor-0.19.1
Parsing documentation for railties-
Installing ri documentation for railties-
Parsing documentation for bundler-1.11.2
Installing ri documentation for bundler-1.11.2
Parsing documentation for concurrent-ruby-1.0.0
Installing ri documentation for concurrent-ruby-1.0.0
Parsing documentation for sprockets-3.5.2
Installing ri documentation for sprockets-3.5.2
Parsing documentation for sprockets-rails-3.0.1
Installing ri documentation for sprockets-rails-3.0.1
Parsing documentation for rails-
unable to convert "\xFF" from ASCII-8BIT to UTF-8 for guides/assets/images/akshaysurve.jpg, skipping
unable to convert "\x89" from ASCII-8BIT to UTF-8 for guides/assets/images/belongs_to.png, skipping
unable to convert "\xF4" from ASCII-8BIT to UTF-8 for guides/assets/images/book_icon.gif, skipping
unable to convert "\x91" from ASCII-8BIT to UTF-8 for guides/assets/images/bullet.gif, skipping
...continued on and on...
unable to convert "\x80" from ASCII-8BIT to UTF-8 for guides/assets/images/tab_yellow.gif, skipping
unable to convert "\x89" from ASCII-8BIT to UTF-8 for guides/assets/images/tab_yellow.png, skipping
unable to convert "\xFF" from ASCII-8BIT to UTF-8 for guides/assets/images/vijaydev.jpg, skipping
Installing ri documentation for rails-
31 gems installed

But, it worked:

$ rails --version

Create Your Application and Framework Instance

Then I created a new application called blog:

$ rails new blog
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/views/layouts/application.html.erb
      create  app/assets/images/.keep
      create  app/mailers/.keep
      create  app/models/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/secrets.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/session_store.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/robots.txt
      create  test/fixtures
      create  test/fixtures/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/test_helper.rb
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.keep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.keep
         run  bundle install

Your user account isn't allowed to install to the system Rubygems.
  You can cancel this installation and run:

      bundle install --path vendor/bundle

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to Rubygems using sudo.

Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies....
Rubygems 2.0.14 is not threadsafe, so your gems will be installed one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem installation.
Installing rake 10.5.0
Using i18n 0.7.0
Installing json 1.8.3 with native extensions
Using minitest 5.8.4
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0
Using rack 1.6.4
Using mime-types 2.99
Using arel 6.0.3
Installing debug_inspector 0.0.2 with native extensions
Using bundler 1.11.2
Installing byebug 8.2.2 with native extensions
Installing coffee-script-source 1.10.0
Installing execjs 2.6.0
Using thor 0.19.1
Using concurrent-ruby 1.0.0
Installing multi_json 1.11.2
Installing sass 3.4.21
Installing tilt 2.0.2
Installing spring 1.6.3
Installing sqlite3 1.3.11 with native extensions
Installing rdoc 4.2.1
Using tzinfo 1.2.2
Using nokogiri
Using rack-test 0.6.3
Using mail 2.6.3
Installing binding_of_caller 0.7.2 with native extensions
Installing coffee-script 2.4.1
Installing uglifier 2.7.2
Using sprockets 3.5.2
Installing sdoc 0.4.1
Using activesupport
Using loofah 2.0.3
Using rails-deprecated_sanitizer 1.0.3
Using globalid 0.3.6
Using activemodel
Installing jbuilder 2.4.0
Using rails-html-sanitizer 1.0.3
Using rails-dom-testing 1.0.7
Using activejob
Using activerecord
Using actionview
Using actionpack
Using actionmailer
Using railties
Using sprockets-rails 3.0.1
Installing coffee-rails 4.1.1
Installing jquery-rails 4.1.0
Using rails
Installing sass-rails 5.0.4
Installing web-console 2.3.0
Installing turbolinks 2.5.3
Bundle complete! 12 Gemfile dependencies, 54 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
         run  bundle exec spring binstub --all
Warning: You're using Rubygems 2.0.14 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
* bin/rake: spring inserted
* bin/rails: spring inserted

You can browse the Rails web application framework directory structure within your application:

$ cd blog
$ ls
Gemfile         Rakefile        config          lib             test
Gemfile.lock    app             config.ru       log             tmp
README.rdoc     bin             db              public          vendor

Here’s a view from the Getting Started guide showing how Rails relies on convention over configuration:

What is Ruby on Rails Directory Structure Convention

Launch Your Server

Finally, you can launch your server with a command line:

$ bin/rails server
Warning: You're using Rubygems 2.0.14 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
=> Booting WEBrick
=> Rails application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-02-05 18:14:05] INFO  WEBrick 1.3.1
[2016-02-05 18:14:05] INFO  ruby 2.0.0 (2015-04-13) [universal.x86_64-darwin15]
[2016-02-05 18:14:05] INFO  WEBrick::HTTPServer#start: pid=30576 port=3000

Visit Your Application

In your browser, go to http://localhost:3000, and you should see your default home page for a generic Rails application:

What is Ruby on Rails Welcome Page of New Application

I have to say, I wish all this was a bit cleaner. That said, there are some wonderful community resources to help you grow.

Going Deeper

Here’s an example of a free GoRails screencast covering the basic framework application architecture shown in the directory above:

And the Rails Guide itself walks you through a number of beginning steps:

What is Ruby on Rails The Getting Started Guide Table of Contents

Overall, there are a wide variety of written and screencast tutorials out there to guide you.

In Closing

If you’re intrigued by the quality of Ruby on Rails and its community, I hope you’ve found this introduction a helpful starting point. Maybe you’ve even tried the install above.

More recently, I’m intrigued by Apple’s open sourcing of Swift, an exciting entrant into the object oriented programming language space, akin to Ruby with similar long-term potential to Rails.

While I’ve worked with Rails in the past, I’ve also had struggles with it, especially with hosting and expanding functionality — I’ve also found hosting it more expensive. I continue to be most comfortable with Yii, which you can read about in our Envato Tuts+ Yii2 Programming Series. And with PHP 7 emerging, the future looks faster and brighter for PHP-based programming frameworks.

If you have questions, please post them below. Or, you can contact me on Twitter @reifman. Please check out my Envato Tuts+ instructor page to see other tutorials I’ve written, such as Using Social Media to Locate Eyewitnesses, which highlights the APIs of Instagram and Twitter.

Related Links

  • Ruby on Rails
  • Ruby on Rails (Wikipedia)
  • Follow @Rails on Twitter
  • Subscribe to This Week in Rails
  • Go Rails (screencasts and more)
  • Ruby Programming Language (Wikipedia)
  • Model View Controller (Wikipedia)
  • RailsConf

Leave a Reply

Your email address will not be published. Required fields are marked *