1. Code
  2. Coding Fundamentals
  3. OOP

What Is Ruby on Rails?

Wonder what all the hype is about? Come learn about the Ruby on Rails web development framework and what you can use it for.
Scroll to top

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 funWhat is Ruby on Rails Sample Rails Apps with Juggler for funWhat 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 RecordWhat is Ruby on Rails The Action Pack View Controller RecordWhat 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 DoctrineWhat is Ruby on Rails The Rails DoctrineWhat 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 TeamWhat is Ruby on Rails The Core TeamWhat is Ruby on Rails The Core Team

And they do have a warm, welcoming community:

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 StartedWhat is Ruby on Rails Getting StartedWhat 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:

1
$ ruby -v
2
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):

1
$ sudo gem install rails
2
Password:
3
Fetching: thread_safe-0.3.5.gem (100%)
4
Successfully installed thread_safe-0.3.5
5
Fetching: tzinfo-1.2.2.gem (100%)
6
Successfully installed tzinfo-1.2.2
7
Fetching: minitest-5.8.4.gem (100%)
8
Successfully installed minitest-5.8.4
9
Fetching: activesupport-4.2.5.1.gem (100%)
10
Successfully installed activesupport-4.2.5.1
11
Fetching: rack-1.6.4.gem (100%)
12
Successfully installed rack-1.6.4
13
Fetching: rack-test-0.6.3.gem (100%)
14
Successfully installed rack-test-0.6.3
15
Fetching: mini_portile2-2.0.0.gem (100%)
16
Successfully installed mini_portile2-2.0.0
17
Fetching: nokogiri-1.6.7.2.gem (100%)
18
Building native extensions.  This could take a while...
19
Successfully installed nokogiri-1.6.7.2
20
Fetching: loofah-2.0.3.gem (100%)
21
Successfully installed loofah-2.0.3
22
Fetching: rails-html-sanitizer-1.0.3.gem (100%)
23
Successfully installed rails-html-sanitizer-1.0.3
24
Fetching: rails-deprecated_sanitizer-1.0.3.gem (100%)
25
Successfully installed rails-deprecated_sanitizer-1.0.3
26
Fetching: rails-dom-testing-1.0.7.gem (100%)
27
Successfully installed rails-dom-testing-1.0.7
28
Fetching: builder-3.2.2.gem (100%)
29
Successfully installed builder-3.2.2
30
Fetching: erubis-2.7.0.gem (100%)
31
Successfully installed erubis-2.7.0
32
Fetching: actionview-4.2.5.1.gem (100%)
33
Successfully installed actionview-4.2.5.1
34
Fetching: actionpack-4.2.5.1.gem (100%)
35
Successfully installed actionpack-4.2.5.1
36
Fetching: activemodel-4.2.5.1.gem (100%)
37
Successfully installed activemodel-4.2.5.1
38
Fetching: arel-6.0.3.gem (100%)
39
Successfully installed arel-6.0.3
40
Fetching: activerecord-4.2.5.1.gem (100%)
41
Successfully installed activerecord-4.2.5.1
42
Fetching: globalid-0.3.6.gem (100%)
43
Successfully installed globalid-0.3.6
44
Fetching: activejob-4.2.5.1.gem (100%)
45
Successfully installed activejob-4.2.5.1
46
Fetching: mime-types-2.99.gem (100%)
47
Successfully installed mime-types-2.99
48
Fetching: mail-2.6.3.gem (100%)
49
Successfully installed mail-2.6.3
50
Fetching: actionmailer-4.2.5.1.gem (100%)
51
Successfully installed actionmailer-4.2.5.1
52
Fetching: thor-0.19.1.gem (100%)
53
Successfully installed thor-0.19.1
54
Fetching: railties-4.2.5.1.gem (100%)
55
Successfully installed railties-4.2.5.1
56
Fetching: bundler-1.11.2.gem (100%)
57
Successfully installed bundler-1.11.2
58
Fetching: concurrent-ruby-1.0.0.gem (100%)
59
Successfully installed concurrent-ruby-1.0.0
60
Fetching: sprockets-3.5.2.gem (100%)
61
Successfully installed sprockets-3.5.2
62
Fetching: sprockets-rails-3.0.1.gem (100%)
63
Successfully installed sprockets-rails-3.0.1
64
Fetching: rails-4.2.5.1.gem (100%)
65
Successfully installed rails-4.2.5.1
66
Parsing documentation for thread_safe-0.3.5
67
Installing ri documentation for thread_safe-0.3.5
68
Parsing documentation for tzinfo-1.2.2
69
Installing ri documentation for tzinfo-1.2.2
70
Parsing documentation for minitest-5.8.4
71
Installing ri documentation for minitest-5.8.4
72
Parsing documentation for activesupport-4.2.5.1
73
unable to convert "\x84" from ASCII-8BIT to UTF-8 for lib/active_support/values/unicode_tables.dat, skipping
74
Installing ri documentation for activesupport-4.2.5.1
75
Parsing documentation for rack-1.6.4
76
Installing ri documentation for rack-1.6.4
77
Parsing documentation for rack-test-0.6.3
78
Installing ri documentation for rack-test-0.6.3
79
Parsing documentation for mini_portile2-2.0.0
80
Installing ri documentation for mini_portile2-2.0.0
81
Parsing documentation for nokogiri-1.6.7.2
82
unable to convert "\xCA" from ASCII-8BIT to UTF-8 for lib/nokogiri/nokogiri.bundle, skipping
83
Installing ri documentation for nokogiri-1.6.7.2
84
Parsing documentation for loofah-2.0.3
85
Installing ri documentation for loofah-2.0.3
86
Parsing documentation for rails-html-sanitizer-1.0.3
87
Installing ri documentation for rails-html-sanitizer-1.0.3
88
Parsing documentation for rails-deprecated_sanitizer-1.0.3
89
Installing ri documentation for rails-deprecated_sanitizer-1.0.3
90
Parsing documentation for rails-dom-testing-1.0.7
91
Installing ri documentation for rails-dom-testing-1.0.7
92
Parsing documentation for builder-3.2.2
93
Installing ri documentation for builder-3.2.2
94
Parsing documentation for erubis-2.7.0
95
Installing ri documentation for erubis-2.7.0
96
Parsing documentation for actionview-4.2.5.1
97
Installing ri documentation for actionview-4.2.5.1
98
Parsing documentation for actionpack-4.2.5.1
99
Installing ri documentation for actionpack-4.2.5.1
100
Parsing documentation for activemodel-4.2.5.1
101
Installing ri documentation for activemodel-4.2.5.1
102
Parsing documentation for arel-6.0.3
103
Installing ri documentation for arel-6.0.3
104
Parsing documentation for activerecord-4.2.5.1
105
Installing ri documentation for activerecord-4.2.5.1
106
Parsing documentation for globalid-0.3.6
107
Installing ri documentation for globalid-0.3.6
108
Parsing documentation for activejob-4.2.5.1
109
Installing ri documentation for activejob-4.2.5.1
110
Parsing documentation for mime-types-2.99
111
Installing ri documentation for mime-types-2.99
112
Parsing documentation for mail-2.6.3
113
Installing ri documentation for mail-2.6.3
114
Parsing documentation for actionmailer-4.2.5.1
115
Installing ri documentation for actionmailer-4.2.5.1
116
Parsing documentation for thor-0.19.1
117
Installing ri documentation for thor-0.19.1
118
Parsing documentation for railties-4.2.5.1
119
Installing ri documentation for railties-4.2.5.1
120
Parsing documentation for bundler-1.11.2
121
Installing ri documentation for bundler-1.11.2
122
Parsing documentation for concurrent-ruby-1.0.0
123
Installing ri documentation for concurrent-ruby-1.0.0
124
Parsing documentation for sprockets-3.5.2
125
Installing ri documentation for sprockets-3.5.2
126
Parsing documentation for sprockets-rails-3.0.1
127
Installing ri documentation for sprockets-rails-3.0.1
128
Parsing documentation for rails-4.2.5.1
129
unable to convert "\xFF" from ASCII-8BIT to UTF-8 for guides/assets/images/akshaysurve.jpg, skipping
130
unable to convert "\x89" from ASCII-8BIT to UTF-8 for guides/assets/images/belongs_to.png, skipping
131
unable to convert "\xF4" from ASCII-8BIT to UTF-8 for guides/assets/images/book_icon.gif, skipping
132
unable to convert "\x91" from ASCII-8BIT to UTF-8 for guides/assets/images/bullet.gif, skipping
133
...
134
...continued on and on...
135
...
136
unable to convert "\x80" from ASCII-8BIT to UTF-8 for guides/assets/images/tab_yellow.gif, skipping
137
unable to convert "\x89" from ASCII-8BIT to UTF-8 for guides/assets/images/tab_yellow.png, skipping
138
unable to convert "\xFF" from ASCII-8BIT to UTF-8 for guides/assets/images/vijaydev.jpg, skipping
139
Installing ri documentation for rails-4.2.5.1
140
31 gems installed

But, it worked:

1
$ rails --version
2
Rails 4.2.5.1

Create Your Application and Framework Instance

Then I created a new application called blog:

1
$ rails new blog
2
      create  
3
      create  README.rdoc
4
      create  Rakefile
5
      create  config.ru
6
      create  .gitignore
7
      create  Gemfile
8
      create  app
9
      create  app/assets/javascripts/application.js
10
      create  app/assets/stylesheets/application.css
11
      create  app/controllers/application_controller.rb
12
      create  app/helpers/application_helper.rb
13
      create  app/views/layouts/application.html.erb
14
      create  app/assets/images/.keep
15
      create  app/mailers/.keep
16
      create  app/models/.keep
17
      create  app/controllers/concerns/.keep
18
      create  app/models/concerns/.keep
19
      create  bin
20
      create  bin/bundle
21
      create  bin/rails
22
      create  bin/rake
23
      create  bin/setup
24
      create  config
25
      create  config/routes.rb
26
      create  config/application.rb
27
      create  config/environment.rb
28
      create  config/secrets.yml
29
      create  config/environments
30
      create  config/environments/development.rb
31
      create  config/environments/production.rb
32
      create  config/environments/test.rb
33
      create  config/initializers
34
      create  config/initializers/assets.rb
35
      create  config/initializers/backtrace_silencers.rb
36
      create  config/initializers/cookies_serializer.rb
37
      create  config/initializers/filter_parameter_logging.rb
38
      create  config/initializers/inflections.rb
39
      create  config/initializers/mime_types.rb
40
      create  config/initializers/session_store.rb
41
      create  config/initializers/wrap_parameters.rb
42
      create  config/locales
43
      create  config/locales/en.yml
44
      create  config/boot.rb
45
      create  config/database.yml
46
      create  db
47
      create  db/seeds.rb
48
      create  lib
49
      create  lib/tasks
50
      create  lib/tasks/.keep
51
      create  lib/assets
52
      create  lib/assets/.keep
53
      create  log
54
      create  log/.keep
55
      create  public
56
      create  public/404.html
57
      create  public/422.html
58
      create  public/500.html
59
      create  public/favicon.ico
60
      create  public/robots.txt
61
      create  test/fixtures
62
      create  test/fixtures/.keep
63
      create  test/controllers
64
      create  test/controllers/.keep
65
      create  test/mailers
66
      create  test/mailers/.keep
67
      create  test/models
68
      create  test/models/.keep
69
      create  test/helpers
70
      create  test/helpers/.keep
71
      create  test/integration
72
      create  test/integration/.keep
73
      create  test/test_helper.rb
74
      create  tmp/cache
75
      create  tmp/cache/assets
76
      create  vendor/assets/javascripts
77
      create  vendor/assets/javascripts/.keep
78
      create  vendor/assets/stylesheets
79
      create  vendor/assets/stylesheets/.keep
80
         run  bundle install

81


82


83
Your user account isn't allowed to install to the system Rubygems.

84
  You can cancel this installation and run:

85


86
      bundle install --path vendor/bundle

87


88
  to install the gems into ./vendor/bundle/, or you can enter your password

89
  and install the bundled gems to Rubygems using sudo.

90


91
  Password: 

92
Fetching gem metadata from https://rubygems.org/...........

93
Fetching version metadata from https://rubygems.org/...

94
Fetching dependency metadata from https://rubygems.org/..

95
Resolving dependencies....

96
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.

97
Installing rake 10.5.0

98
Using i18n 0.7.0

99
Installing json 1.8.3 with native extensions

100
Using minitest 5.8.4

101
Using thread_safe 0.3.5

102
Using builder 3.2.2

103
Using erubis 2.7.0

104
Using mini_portile2 2.0.0

105
Using rack 1.6.4

106
Using mime-types 2.99

107
Using arel 6.0.3

108
Installing debug_inspector 0.0.2 with native extensions

109
Using bundler 1.11.2

110
Installing byebug 8.2.2 with native extensions

111
Installing coffee-script-source 1.10.0

112
Installing execjs 2.6.0

113
Using thor 0.19.1

114
Using concurrent-ruby 1.0.0

115
Installing multi_json 1.11.2

116
Installing sass 3.4.21

117
Installing tilt 2.0.2

118
Installing spring 1.6.3

119
Installing sqlite3 1.3.11 with native extensions

120
Installing rdoc 4.2.1

121
Using tzinfo 1.2.2

122
Using nokogiri 1.6.7.2

123
Using rack-test 0.6.3

124
Using mail 2.6.3

125
Installing binding_of_caller 0.7.2 with native extensions

126
Installing coffee-script 2.4.1

127
Installing uglifier 2.7.2

128
Using sprockets 3.5.2

129
Installing sdoc 0.4.1

130
Using activesupport 4.2.5.1

131
Using loofah 2.0.3

132
Using rails-deprecated_sanitizer 1.0.3

133
Using globalid 0.3.6

134
Using activemodel 4.2.5.1

135
Installing jbuilder 2.4.0

136
Using rails-html-sanitizer 1.0.3

137
Using rails-dom-testing 1.0.7

138
Using activejob 4.2.5.1

139
Using activerecord 4.2.5.1

140
Using actionview 4.2.5.1

141
Using actionpack 4.2.5.1

142
Using actionmailer 4.2.5.1

143
Using railties 4.2.5.1

144
Using sprockets-rails 3.0.1

145
Installing coffee-rails 4.1.1

146
Installing jquery-rails 4.1.0

147
Using rails 4.2.5.1

148
Installing sass-rails 5.0.4

149
Installing web-console 2.3.0

150
Installing turbolinks 2.5.3

151
Bundle complete! 12 Gemfile dependencies, 54 gems now installed.

152
Use `bundle show [gemname]` to see where a bundled gem is installed.

153
Post-install message from rdoc:

154
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

155


156
<= 1.8.6 : unsupported

157
 = 1.8.7 : gem install rdoc-data; rdoc-data --install

158
 = 1.9.1 : gem install rdoc-data; rdoc-data --install

159
>= 1.9.2 : nothing to do! Yay!

160
         run  bundle exec spring binstub --all

161
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.
162
* bin/rake: spring inserted
163
* bin/rails: spring inserted

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

1
$ cd blog
2
$ ls

3
Gemfile    	Rakefile	config		lib		test

4
Gemfile.lock	app		config.ru	log		tmp
5
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 ConventionWhat is Ruby on Rails Directory Structure ConventionWhat is Ruby on Rails Directory Structure Convention

Launch Your Server

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

1
$ bin/rails server
2
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.

3
=> Booting WEBrick

4
=> Rails 4.2.5.1 application starting in development on http://localhost:3000

5
=> Run `rails server -h` for more startup options

6
=> Ctrl-C to shutdown server

7
[2016-02-05 18:14:05] INFO  WEBrick 1.3.1

8
[2016-02-05 18:14:05] INFO  ruby 2.0.0 (2015-04-13) [universal.x86_64-darwin15]

9
[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 ApplicationWhat is Ruby on Rails Welcome Page of New ApplicationWhat 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:

Please accept marketing cookies to load this content.

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

What is Ruby on Rails The Getting Started Guide Table of ContentsWhat is Ruby on Rails The Getting Started Guide Table of ContentsWhat 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