SlideShare a Scribd company logo
RUBY ON RAILS
AN INTRODUCTION TO RAILS 3
CREATING YOUR FIRST RAILS APP

               rails new roster

      This command generates code for
          a new Rails web application 
       in a sub-directory called “roster”  
THE APPLICATION DIRECTORY
• The whole rails app is in this one directory
  • No hidden configuration files in system directories
  • You will modify many of these files in the course of your development
  • We're using sqlite so even the database is in this directory, but usually the
    database is the only part of your application that lives somewhere else
• You can simple copy this directory to server to deploy the app
• You can delete the directory and its contents
  if you want to throw it away and start over
RUNNING YOUR APP

      cd roster
       bundle
     rails server 
RAILS ENVIRONMENTS
By default, Rails is configured with 3 environments:
   • development
   • test
   • production
RAILS ENVIRONMENTS
RAILS ENVIRONMENTS
RAILS ENVIRONMENTS
The environment can be specified with

 RAILS_ENV as an environment variable
  "development" by default.

In your code, you refer to Rails.env
(or RAILS_ENV in Rails 2)
CONFIG/DATABASE.YML
ADDITIONAL CONFIGURATION


config/environments/
   • development.rb
   • production.rb
   • test.rb
MODIFYING THE HOME PAGE

           public/index.html

     All files in the public directory
            are static content.

       Rails checks this directory
   before executing any dynamic code.
MVC
LEARNING WITH SCAFFOLD


rails generate scaffold
   person first_name:string last_name:string
NAMING CONVENTIONS
SCAFFOLD
Model
  app/models/person.rb
  db/migrate/20090611073227_create_people.rb

5 views
    app/views/people/index.html.erb
    app/views/people/show.html.erb
    app/views/people/new.html.erb
    app/views/people/edit.html.erb
    app/views/people/_form.html.erb

Controller
   app/controllers/people_controller.rb
   route.rb: resources :people
MVC
Model: ActiveRecord
• Represents what is in the database

View: ActionView, erb
• Model rendered as HTML

Controller: ActionController
• Receives HTTP actions (GET, POST, PUT, DELETE)
• Decides what to do, typically rendering a view
VIEWS

<% @people.each do |person| %>
<tr>

 <td><%= person.first_name %></td>
   <td><%= person.last_name %></td>
</tr>
<% end %>
VIEW EXERCISE

On the main people page 

 a. Change “Listing people” to “My Class List” 

 b. List people with first initial and last name in one visual
  column (e.g. W. Flintstone) 

More Related Content

PDF
Your first rails app - 2
PDF
CHEF - by Scott Russel
PPTX
CakeFest 2013 - A-Z REST APIs
PPT
Chef - managing yours servers with Code
PDF
2015 08-11-scdo-meetup
PDF
Apikit from command line
PDF
RoR 101: Session 4
PPTX
Spring Cloud Config
Your first rails app - 2
CHEF - by Scott Russel
CakeFest 2013 - A-Z REST APIs
Chef - managing yours servers with Code
2015 08-11-scdo-meetup
Apikit from command line
RoR 101: Session 4
Spring Cloud Config

What's hot (20)

PPTX
Laravel
KEY
深入淺出RoR
KEY
Cocoa on-rails-3rd
PDF
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
PPTX
API Development with Laravel
PDF
Memphis php 01 22-13 - laravel basics
PDF
Curso rails
PPT
Rail3 intro 29th_sep_surendran
PDF
Project Fedena and Why Ruby on Rails - ArvindArvind G S
PPTX
Basic React Knowledge.
KEY
S2GX 2012 - Spring Projects Infrastructure
PDF
Rails 5 – most effective features for apps upgradation
PDF
Ch. 13 filters and wrappers
PDF
The Spring Update
PPTX
Introduction to laravel framework
PPTX
Rails Engine Patterns
PPT
A Tour of Ruby On Rails
PPT
Weblogic Domain Activity
PDF
Laravel Restful API and AngularJS
PDF
Understanding asset pipeline plugin
Laravel
深入淺出RoR
Cocoa on-rails-3rd
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
API Development with Laravel
Memphis php 01 22-13 - laravel basics
Curso rails
Rail3 intro 29th_sep_surendran
Project Fedena and Why Ruby on Rails - ArvindArvind G S
Basic React Knowledge.
S2GX 2012 - Spring Projects Infrastructure
Rails 5 – most effective features for apps upgradation
Ch. 13 filters and wrappers
The Spring Update
Introduction to laravel framework
Rails Engine Patterns
A Tour of Ruby On Rails
Weblogic Domain Activity
Laravel Restful API and AngularJS
Understanding asset pipeline plugin
Ad

Viewers also liked (20)

PPT
The Potato Story 一袋土豆
KEY
Mobile Lean UX
KEY
Ruby Blocks
KEY
Ruby on rails toolbox
PPT
Mattawa, Ontario, Canada, 1970
KEY
Strings and Symbols
PPT
Ganeshnagar, Huttment Area
KEY
Form helpers
PPT
Living Cities
PPT
China’s Development Pattern as found in its Sacred Literature
PDF
Extending rails
PPTX
The Stream - Where Talent Flows
KEY
Files IO
PPTX
Taoist Temple, Beijing
PPT
Leo Carter: Tibet by Bicycle 2010
PDF
Climogramas mundiales
DOCX
Religion and Sustainable Development in China
PPTX
Secrets to Web Marketing Success
KEY
What you don't know (yet)
KEY
Conditionals
The Potato Story 一袋土豆
Mobile Lean UX
Ruby Blocks
Ruby on rails toolbox
Mattawa, Ontario, Canada, 1970
Strings and Symbols
Ganeshnagar, Huttment Area
Form helpers
Living Cities
China’s Development Pattern as found in its Sacred Literature
Extending rails
The Stream - Where Talent Flows
Files IO
Taoist Temple, Beijing
Leo Carter: Tibet by Bicycle 2010
Climogramas mundiales
Religion and Sustainable Development in China
Secrets to Web Marketing Success
What you don't know (yet)
Conditionals
Ad

Similar to Introduction to Rails (20)

PPT
Rails
 
KEY
Supa fast Ruby + Rails
PPTX
12 Introduction to Rails
PDF
Introduction to Ruby on Rails
PDF
Aspose pdf
PPTX
Laravel overview
PDF
Ruby Rails Web Development
PPT
Jasig rubyon rails
PPT
Jasig rubyon rails
PDF
Lecture #5 Introduction to rails
PDF
Introduction to Rails by Evgeniy Hinyuk
PDF
Ruby On Rails
DOCX
KEY
An introduction to Rails 3
PPT
Ruby on Rails introduction
PPTX
Intro to Rails and MVC
DOC
Rails interview questions
PDF
Ruby on Rails Scaffold_ Create Your App In Minutes
ODP
Migration from Rails2 to Rails3
PDF
Ruby on Rails
Rails
 
Supa fast Ruby + Rails
12 Introduction to Rails
Introduction to Ruby on Rails
Aspose pdf
Laravel overview
Ruby Rails Web Development
Jasig rubyon rails
Jasig rubyon rails
Lecture #5 Introduction to rails
Introduction to Rails by Evgeniy Hinyuk
Ruby On Rails
An introduction to Rails 3
Ruby on Rails introduction
Intro to Rails and MVC
Rails interview questions
Ruby on Rails Scaffold_ Create Your App In Minutes
Migration from Rails2 to Rails3
Ruby on Rails

More from Blazing Cloud (18)

PDF
Rails ORM De-mystifying Active Record has_many
PDF
Active Record Introduction - 3
PDF
Rails Class Intro - 1
PDF
RSpec Quick Reference
KEY
2day Ruby Class Intro
KEY
Interactive Graphics
KEY
Interactive Graphics w/ Javascript, HTML5 and CSS3
KEY
Intro to Ruby (and RSpec)
KEY
ActiveRecord
KEY
Ruby on Rails Class intro
KEY
Routes Controllers
KEY
Test Driven Development
KEY
Active Record
KEY
Enumerables
KEY
KEY
Power Ruby
PDF
Rails 3 ActiveRecord
KEY
Iterators, Hashes, and Arrays
Rails ORM De-mystifying Active Record has_many
Active Record Introduction - 3
Rails Class Intro - 1
RSpec Quick Reference
2day Ruby Class Intro
Interactive Graphics
Interactive Graphics w/ Javascript, HTML5 and CSS3
Intro to Ruby (and RSpec)
ActiveRecord
Ruby on Rails Class intro
Routes Controllers
Test Driven Development
Active Record
Enumerables
Power Ruby
Rails 3 ActiveRecord
Iterators, Hashes, and Arrays

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Spectroscopy.pptx food analysis technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation_ Review paper, used for researhc scholars
Building Integrated photovoltaic BIPV_UPV.pdf
sap open course for s4hana steps from ECC to s4
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Per capita expenditure prediction using model stacking based on satellite ima...
Programs and apps: productivity, graphics, security and other tools
Spectroscopy.pptx food analysis technology
Unlocking AI with Model Context Protocol (MCP)
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25 Week I
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectral efficient network and resource selection model in 5G networks
Advanced methodologies resolving dimensionality complications for autism neur...
MIND Revenue Release Quarter 2 2025 Press Release
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation_ Review paper, used for researhc scholars

Introduction to Rails

  • 1. RUBY ON RAILS AN INTRODUCTION TO RAILS 3
  • 2. CREATING YOUR FIRST RAILS APP rails new roster This command generates code for a new Rails web application  in a sub-directory called “roster”  
  • 3. THE APPLICATION DIRECTORY • The whole rails app is in this one directory • No hidden configuration files in system directories • You will modify many of these files in the course of your development • We're using sqlite so even the database is in this directory, but usually the database is the only part of your application that lives somewhere else • You can simple copy this directory to server to deploy the app • You can delete the directory and its contents if you want to throw it away and start over
  • 4. RUNNING YOUR APP cd roster bundle rails server 
  • 5. RAILS ENVIRONMENTS By default, Rails is configured with 3 environments: • development • test • production
  • 8. RAILS ENVIRONMENTS The environment can be specified with RAILS_ENV as an environment variable "development" by default. In your code, you refer to Rails.env (or RAILS_ENV in Rails 2)
  • 10. ADDITIONAL CONFIGURATION config/environments/ • development.rb • production.rb • test.rb
  • 11. MODIFYING THE HOME PAGE public/index.html All files in the public directory are static content. Rails checks this directory before executing any dynamic code.
  • 12. MVC
  • 13. LEARNING WITH SCAFFOLD rails generate scaffold person first_name:string last_name:string
  • 15. SCAFFOLD Model app/models/person.rb db/migrate/20090611073227_create_people.rb 5 views app/views/people/index.html.erb app/views/people/show.html.erb app/views/people/new.html.erb app/views/people/edit.html.erb app/views/people/_form.html.erb Controller app/controllers/people_controller.rb route.rb: resources :people
  • 16. MVC Model: ActiveRecord • Represents what is in the database View: ActionView, erb • Model rendered as HTML Controller: ActionController • Receives HTTP actions (GET, POST, PUT, DELETE) • Decides what to do, typically rendering a view
  • 17. VIEWS <% @people.each do |person| %> <tr> <td><%= person.first_name %></td> <td><%= person.last_name %></td> </tr> <% end %>
  • 18. VIEW EXERCISE On the main people page  a. Change “Listing people” to “My Class List”  b. List people with first initial and last name in one visual column (e.g. W. Flintstone) 

Editor's Notes