SlideShare a Scribd company logo
YOUR FIRST RAILS APP
                              Environments, MVC, Scaffold




Sunday, November 13, 11
CREATING YOUR FIRST RAILS APP

                                   rails new roster

                          This command generates code for
                              a new Rails web application 
                           in a sub-directory called “roster”  




Sunday, November 13, 11
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




Sunday, November 13, 11
RUNNING YOUR APP

                                cd roster
                                 bundle
                               rails server 




Sunday, November 13, 11
RAILS ENVIRONMENTS
       By default, Rails is configured with 3 environments:
         • development
         • test
         • production




Sunday, November 13, 11
RAILS ENVIRONMENTS




Sunday, November 13, 11
RAILS ENVIRONMENTS




Sunday, November 13, 11
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)




Sunday, November 13, 11
CONFIG/DATABASE.YML




Sunday, November 13, 11
ADDITIONAL CONFIGURATION


   config/environments/
     • development.rb
     • production.rb
     • test.rb




Sunday, November 13, 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.




Sunday, November 13, 11
MVC




Sunday, November 13, 11
LEARNING WITH SCAFFOLD

   rails generate scaffold
      person first_name:string last_name:string




Sunday, November 13, 11
NAMING CONVENTIONS




Sunday, November 13, 11
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

Sunday, November 13, 11
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
Sunday, November 13, 11
VIEWS

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

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




Sunday, November 13, 11
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) 




Sunday, November 13, 11

More Related Content

PDF
Memphis php 01 22-13 - laravel basics
PPTX
Getting started with laravel
PPTX
Laravel ppt
PPT
What Is Hobo ?
PPT
Content Storage With Apache Jackrabbit
PPTX
A introduction to Laravel framework
PDF
Laravel Introduction
PPTX
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Memphis php 01 22-13 - laravel basics
Getting started with laravel
Laravel ppt
What Is Hobo ?
Content Storage With Apache Jackrabbit
A introduction to Laravel framework
Laravel Introduction
Laravel development (Laravel History, Environment Setup & Laravel Installatio...

What's hot (20)

PDF
Laravel presentation
PPT
Ruby on Rails workshop for beginner
PPTX
Laravel overview
PDF
Laravel 5.4
PPTX
Laravel Eloquent ORM
PDF
Weblogic Console Customization
PDF
Weblogic Console Customization labs
PPTX
Laravel Tutorial PPT
PPTX
Mule tcat server - Server profiles
PDF
Laravel
PDF
Getting to know Laravel 5
PDF
JBoss, Rails and the cloud
PDF
Database migration with flyway
ODP
Presentation laravel 5 4
PPTX
MuleSoft ESB Composite Source
PPTX
Laravel introduction
PPTX
Maven Fundamentals
PPTX
MySqL Failover by Weatherly Cloud Computing USA
PDF
Ch. 13 filters and wrappers
PPTX
MySQL Failover - Cubexs Weatherly
Laravel presentation
Ruby on Rails workshop for beginner
Laravel overview
Laravel 5.4
Laravel Eloquent ORM
Weblogic Console Customization
Weblogic Console Customization labs
Laravel Tutorial PPT
Mule tcat server - Server profiles
Laravel
Getting to know Laravel 5
JBoss, Rails and the cloud
Database migration with flyway
Presentation laravel 5 4
MuleSoft ESB Composite Source
Laravel introduction
Maven Fundamentals
MySqL Failover by Weatherly Cloud Computing USA
Ch. 13 filters and wrappers
MySQL Failover - Cubexs Weatherly
Ad

Similar to Your first rails app - 2 (20)

KEY
Introduction to Rails
KEY
Supa fast Ruby + Rails
PDF
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
PDF
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
PPTX
Intro to Rails and MVC
PDF
Connecting the Worlds of Java and Ruby with JRuby
PDF
Rails - getting started
KEY
An introduction to Rails 3
PDF
Lecture #5 Introduction to rails
PDF
Introduction to Rails by Evgeniy Hinyuk
PDF
Aspose pdf
PPT
Rails
 
PDF
Curso rails
PDF
PDF Ruby on Rails 3 Day BC
PDF
Ruby Rails Web Development
PDF
Ruby On Rails Basics
PPT
Ruby On Rails Seminar Basis Softexpo Feb2010
PPT
Ruby On Rails Introduction
PDF
Ruby on Rails
PDF
Ruby On Rails
Introduction to Rails
Supa fast Ruby + Rails
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Intro to Rails and MVC
Connecting the Worlds of Java and Ruby with JRuby
Rails - getting started
An introduction to Rails 3
Lecture #5 Introduction to rails
Introduction to Rails by Evgeniy Hinyuk
Aspose pdf
Rails
 
Curso rails
PDF Ruby on Rails 3 Day BC
Ruby Rails Web Development
Ruby On Rails Basics
Ruby On Rails Seminar Basis Softexpo Feb2010
Ruby On Rails Introduction
Ruby on Rails
Ruby On Rails
Ad

More from Blazing Cloud (20)

PDF
Rails ORM De-mystifying Active Record has_many
PDF
Active Record Introduction - 3
PDF
Rails Class Intro - 1
PDF
RSpec Quick Reference
PDF
Extending rails
KEY
2day Ruby Class Intro
KEY
Mobile Lean UX
KEY
Interactive Graphics
KEY
Interactive Graphics w/ Javascript, HTML5 and CSS3
KEY
Form helpers
KEY
Intro to Ruby (and RSpec)
KEY
What you don't know (yet)
KEY
ActiveRecord
KEY
Ruby on Rails Class intro
KEY
Ruby on rails toolbox
KEY
Routes Controllers
KEY
Test Driven Development
KEY
Active Record
KEY
Enumerables
KEY
Rails ORM De-mystifying Active Record has_many
Active Record Introduction - 3
Rails Class Intro - 1
RSpec Quick Reference
Extending rails
2day Ruby Class Intro
Mobile Lean UX
Interactive Graphics
Interactive Graphics w/ Javascript, HTML5 and CSS3
Form helpers
Intro to Ruby (and RSpec)
What you don't know (yet)
ActiveRecord
Ruby on Rails Class intro
Ruby on rails toolbox
Routes Controllers
Test Driven Development
Active Record
Enumerables

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
cuic standard and advanced reporting.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Spectroscopy.pptx food analysis technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
KodekX | Application Modernization Development
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Empathic Computing: Creating Shared Understanding
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Cloud computing and distributed systems.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Building Integrated photovoltaic BIPV_UPV.pdf
The AUB Centre for AI in Media Proposal.docx
The Rise and Fall of 3GPP – Time for a Sabbatical?
cuic standard and advanced reporting.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Spectroscopy.pptx food analysis technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KodekX | Application Modernization Development
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Network Security Unit 5.pdf for BCA BBA.
NewMind AI Weekly Chronicles - August'25 Week I
Empathic Computing: Creating Shared Understanding
Per capita expenditure prediction using model stacking based on satellite ima...
Cloud computing and distributed systems.
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Your first rails app - 2

  • 1. YOUR FIRST RAILS APP Environments, MVC, Scaffold Sunday, November 13, 11
  • 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”   Sunday, November 13, 11
  • 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 Sunday, November 13, 11
  • 4. RUNNING YOUR APP cd roster bundle rails server  Sunday, November 13, 11
  • 5. RAILS ENVIRONMENTS By default, Rails is configured with 3 environments: • development • test • production Sunday, November 13, 11
  • 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) Sunday, November 13, 11
  • 10. ADDITIONAL CONFIGURATION config/environments/ • development.rb • production.rb • test.rb Sunday, November 13, 11
  • 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. Sunday, November 13, 11
  • 13. LEARNING WITH SCAFFOLD rails generate scaffold person first_name:string last_name:string Sunday, November 13, 11
  • 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 Sunday, November 13, 11
  • 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 Sunday, November 13, 11
  • 17. VIEWS <% @people.each do |person| %> <tr> <td><%= person.first_name %></td> <td><%= person.last_name %></td> </tr> <% end %> Sunday, November 13, 11
  • 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)  Sunday, November 13, 11