SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

JBoss, Rails and the cloud
JBoss, Rails and the cloudJBoss, Rails and the cloud
JBoss, Rails and the cloud
elliando dias
 
Ch. 13 filters and wrappers
Ch. 13 filters and wrappersCh. 13 filters and wrappers
Ch. 13 filters and wrappers
Manolis Vavalis
 

Was ist angesagt? (20)

Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
 
Ruby on Rails workshop for beginner
Ruby on Rails workshop for beginnerRuby on Rails workshop for beginner
Ruby on Rails workshop for beginner
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
Laravel 5.4
Laravel 5.4 Laravel 5.4
Laravel 5.4
 
Laravel Eloquent ORM
Laravel Eloquent ORMLaravel Eloquent ORM
Laravel Eloquent ORM
 
Weblogic Console Customization
Weblogic Console CustomizationWeblogic Console Customization
Weblogic Console Customization
 
Weblogic Console Customization labs
Weblogic Console Customization labsWeblogic Console Customization labs
Weblogic Console Customization labs
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Mule tcat server - Server profiles
Mule tcat server - Server profilesMule tcat server - Server profiles
Mule tcat server - Server profiles
 
Laravel
LaravelLaravel
Laravel
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
JBoss, Rails and the cloud
JBoss, Rails and the cloudJBoss, Rails and the cloud
JBoss, Rails and the cloud
 
Database migration with flyway
Database migration  with flywayDatabase migration  with flyway
Database migration with flyway
 
Presentation laravel 5 4
Presentation laravel 5 4Presentation laravel 5 4
Presentation laravel 5 4
 
MuleSoft ESB Composite Source
MuleSoft ESB Composite SourceMuleSoft ESB Composite Source
MuleSoft ESB Composite Source
 
Laravel introduction
Laravel introductionLaravel introduction
Laravel introduction
 
Maven Fundamentals
Maven FundamentalsMaven Fundamentals
Maven Fundamentals
 
MySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USAMySqL Failover by Weatherly Cloud Computing USA
MySqL Failover by Weatherly Cloud Computing USA
 
Ch. 13 filters and wrappers
Ch. 13 filters and wrappersCh. 13 filters and wrappers
Ch. 13 filters and wrappers
 
MySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs WeatherlyMySQL Failover - Cubexs Weatherly
MySQL Failover - Cubexs Weatherly
 

Ähnlich wie Your first rails app - 2

Unlocked London - Technical Track
Unlocked London - Technical TrackUnlocked London - Technical Track
Unlocked London - Technical Track
Wayne Walls
 
Rails
RailsRails
Rails
SHC
 
Building Application With Ruby On Rails Framework
Building Application With Ruby On Rails FrameworkBuilding Application With Ruby On Rails Framework
Building Application With Ruby On Rails Framework
Vineet Chaturvedi
 

Ähnlich wie Your first rails app - 2 (20)

Active Record Introduction - 3
Active Record Introduction - 3Active Record Introduction - 3
Active Record Introduction - 3
 
Introduction to Rails
Introduction to RailsIntroduction to Rails
Introduction to Rails
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_many
 
Activiti & Vaddin
Activiti & VaddinActiviti & Vaddin
Activiti & Vaddin
 
Aspose pdf
Aspose pdfAspose pdf
Aspose pdf
 
Curso rails
Curso railsCurso rails
Curso rails
 
Unlocked London - Technical Track
Unlocked London - Technical TrackUnlocked London - Technical Track
Unlocked London - Technical Track
 
Rails
RailsRails
Rails
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
CloudFoundry and MongoDb, a marriage made in heaven
CloudFoundry and MongoDb, a marriage made in heavenCloudFoundry and MongoDb, a marriage made in heaven
CloudFoundry and MongoDb, a marriage made in heaven
 
Rail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendranRail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendran
 
Building Application With Ruby On Rails Framework
Building Application With Ruby On Rails FrameworkBuilding Application With Ruby On Rails Framework
Building Application With Ruby On Rails Framework
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Building Application with Ruby On Rails Framework
Building Application with Ruby On Rails FrameworkBuilding Application with Ruby On Rails Framework
Building Application with Ruby On Rails Framework
 
Coding For Config: Install Profile Development Using Features
Coding For Config: Install Profile Development Using FeaturesCoding For Config: Install Profile Development Using Features
Coding For Config: Install Profile Development Using Features
 
An introduction to Rails 3
An introduction to Rails 3An introduction to Rails 3
An introduction to Rails 3
 
Pocket Knife JS
Pocket Knife JSPocket Knife JS
Pocket Knife JS
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 

Mehr von Blazing Cloud

RSpec Quick Reference
RSpec Quick ReferenceRSpec Quick Reference
RSpec Quick Reference
Blazing Cloud
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
Blazing Cloud
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Blazing Cloud
 

Mehr von Blazing Cloud (20)

Rails Class Intro - 1
Rails Class Intro - 1 Rails Class Intro - 1
Rails Class Intro - 1
 
RSpec Quick Reference
RSpec Quick ReferenceRSpec Quick Reference
RSpec Quick Reference
 
Extending rails
Extending railsExtending rails
Extending rails
 
2day Ruby Class Intro
2day Ruby Class Intro2day Ruby Class Intro
2day Ruby Class Intro
 
Mobile Lean UX
Mobile Lean UXMobile Lean UX
Mobile Lean UX
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
 
Interactive Graphics w/ Javascript, HTML5 and CSS3
Interactive Graphics w/ Javascript, HTML5 and CSS3Interactive Graphics w/ Javascript, HTML5 and CSS3
Interactive Graphics w/ Javascript, HTML5 and CSS3
 
Form helpers
Form helpersForm helpers
Form helpers
 
Intro to Ruby (and RSpec)
Intro to Ruby (and RSpec)Intro to Ruby (and RSpec)
Intro to Ruby (and RSpec)
 
What you don't know (yet)
What you don't know (yet)What you don't know (yet)
What you don't know (yet)
 
ActiveRecord
ActiveRecordActiveRecord
ActiveRecord
 
Ruby on Rails Class intro
Ruby on Rails Class introRuby on Rails Class intro
Ruby on Rails Class intro
 
Ruby on rails toolbox
Ruby on rails toolboxRuby on rails toolbox
Ruby on rails toolbox
 
Routes Controllers
Routes ControllersRoutes Controllers
Routes Controllers
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Active Record
Active RecordActive Record
Active Record
 
Enumerables
EnumerablesEnumerables
Enumerables
 
Reg EX
Reg EXReg EX
Reg EX
 
Files IO
Files IOFiles IO
Files IO
 
Ruby Blocks
Ruby BlocksRuby Blocks
Ruby Blocks
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

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