SlideShare une entreprise Scribd logo
1  sur  21
The 13th Round of ROR Lab.


   Rails Routing
from the Outside In
         (1)
         May 26th, 2012

         Hyoseong Choi
           ROR Lab.
Rails Router
   http://blog.org


  _path           _url




   A Controller Action



                         ROR Lab.
$ rake routes

    posts GET    /posts(.:format)          posts#index
          POST   /posts(.:format)          posts#create
 new_post GET    /posts/new(.:format)      posts#new
edit_post GET    /posts/:id/edit(.:format) posts#edit
     post GET    /posts/:id(.:format)      posts#show
          PUT    /posts/:id(.:format)      posts#update
          DELETE /posts/:id(.:format)      posts#destroy




                                                        ROR Lab.
An Incoming Request

    GET /posts/17



         ?
                    ROR Lab.
Generating
   paths & URLs
@patient = Patient.find(17)




<%= link_to "Patient Record", patient_path(@patient) %>




         URL = host + port + PATH

                                                          ROR Lab.
Resource Routing
• Action 7 brothers
• index / show / new / edit
  create / update / destroy
                           in config/routes.rb

   resources :photos



“sine” - show, index, new, edit
                                            ROR Lab.
An Incoming Request

  DELETE /posts/17



        ?
                     ROR Lab.
HTTP verbs
                         new      create      C
           • POST
                                              R
           • GET
                        index     show
URL
           • PUT        update                U
           • DELETE
                        destroy               D
Note : routing orders                      ROR Lab.
Multiple Resources

 resources :photos
 resources :books
 resources :videos




 resources :photos, :books, :videos




                                      ROR Lab.
Singular Resources

 match "profile" => "users#show"




 resource :geocoder




                                  ROR Lab.
Singular Resources
  resource :geocoder




 Action 6 brothers     no index action




                                         ROR Lab.
Controller
      Namespacing
Admin:: module prefix

   namespace :admin do
     resources :posts, :comments




   scope :module => "admin" do
     resources :posts, :comments




   scope "/admin" do
     resources :posts, :comments



                                   ROR Lab.
Controller
   Namespacing
namespace :admin do
  resources :posts, :comments
                                Admin:: module prefix




                                                 ROR Lab.
Controller
   Namespacing
scope :module => "admin" do
  resources :posts, :comments
                                Admin:: module prefix




                                                 ROR Lab.
Controller
   Namespacing
scope "/admin" do
  resources :posts, :comments
                           without Admin:: module prefix




                                                    ROR Lab.
Nested Resources
 class Magazine < ActiveRecord::Base
   has_many :ads
 end
  
 class Ad < ActiveRecord::Base
   belongs_to :magazine




 resources :magazines do
   resources :ads




                                       ROR Lab.
Nested Resources
         resources :magazines do
           resources :ads




                             ROR Lab.
Paths & URLs
     From Objects
<%= link_to "Ad details", magazine_ad_path(@magazine, @ad) %>




<%= link_to "Ad details", url_for([@magazine, @ad]) %>




<%= link_to "Ad details", [@magazine, @ad] %>




                                                                ROR Lab.
More RESTful
       Actions
• Member Routes
 resources :photos do
   member do
     get 'preview'
   end




 URL : /photos/1/preview with GET

 Named Routes
     : preview_photo_url and preview_photo_path



                                                  ROR Lab.
More RESTful
       Actions
• Collection Routes
 resources :photos do
   collection do
     get 'search'
   end




 URL : /photos/search with GET

 Named Routes
     : search_photos_url and search_photos_path



                                                  ROR Lab.
감사합니다.

Contenu connexe

Tendances

Flask patterns
Flask patternsFlask patterns
Flask patterns
it-people
 
Head First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & ApplicationHead First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & Application
Jace Ju
 
深入淺出 MVC
深入淺出 MVC深入淺出 MVC
深入淺出 MVC
Jace Ju
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
Compare Infobase Limited
 

Tendances (20)

REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Flask patterns
Flask patternsFlask patterns
Flask patterns
 
Pourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirent
 
Getting Started-with-Laravel
Getting Started-with-LaravelGetting Started-with-Laravel
Getting Started-with-Laravel
 
Head First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & ApplicationHead First Zend Framework - Part 1 Project & Application
Head First Zend Framework - Part 1 Project & Application
 
Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2
 
XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話XamarinとAWSをつないでみた話
XamarinとAWSをつないでみた話
 
Zend framework
Zend frameworkZend framework
Zend framework
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
 
Introduction to plugin development
Introduction to plugin developmentIntroduction to plugin development
Introduction to plugin development
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 
深入淺出 MVC
深入淺出 MVC深入淺出 MVC
深入淺出 MVC
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014
 
Flask - Backend com Python - Semcomp 18
Flask - Backend com Python - Semcomp 18Flask - Backend com Python - Semcomp 18
Flask - Backend com Python - Semcomp 18
 

En vedette

Rails Routing and URL design
Rails Routing and URL designRails Routing and URL design
Rails Routing and URL design
hiq5
 
20120121 rbc rails_routing
20120121 rbc rails_routing20120121 rbc rails_routing
20120121 rbc rails_routing
Takeshi AKIMA
 
Rails training presentation routing
Rails training presentation   routingRails training presentation   routing
Rails training presentation routing
theacadian
 
Mapas conceptuales .... doc
Mapas conceptuales .... docMapas conceptuales .... doc
Mapas conceptuales .... doc
Jedaxbarrera
 
11 vocabulary
11 vocabulary11 vocabulary
11 vocabulary
ihsan
 
Aantal klachten van asielzoekers in België verdrievoudigd op jaar tijd
Aantal klachten van asielzoekers in België verdrievoudigd op jaar tijdAantal klachten van asielzoekers in België verdrievoudigd op jaar tijd
Aantal klachten van asielzoekers in België verdrievoudigd op jaar tijd
Thierry Debels
 

En vedette (19)

Rails Routing and URL design
Rails Routing and URL designRails Routing and URL design
Rails Routing and URL design
 
20120121 rbc rails_routing
20120121 rbc rails_routing20120121 rbc rails_routing
20120121 rbc rails_routing
 
Rails Routing And Rendering
Rails Routing And RenderingRails Routing And Rendering
Rails Routing And Rendering
 
Rails training presentation routing
Rails training presentation   routingRails training presentation   routing
Rails training presentation routing
 
Routing
RoutingRouting
Routing
 
Visible Banking - Social Media, People First (April 2009)
Visible Banking - Social Media, People First (April 2009)Visible Banking - Social Media, People First (April 2009)
Visible Banking - Social Media, People First (April 2009)
 
Apresentação s. martinho
Apresentação s. martinhoApresentação s. martinho
Apresentação s. martinho
 
A idade e a mudança lya luft
A idade e a mudança lya luftA idade e a mudança lya luft
A idade e a mudança lya luft
 
Leveraging Social Media to Reach B2B Customers
Leveraging Social Media to Reach B2B CustomersLeveraging Social Media to Reach B2B Customers
Leveraging Social Media to Reach B2B Customers
 
Mapas conceptuales .... doc
Mapas conceptuales .... docMapas conceptuales .... doc
Mapas conceptuales .... doc
 
11 vocabulary
11 vocabulary11 vocabulary
11 vocabulary
 
Acrylic Painting - Somewhere Yellow
Acrylic Painting - Somewhere YellowAcrylic Painting - Somewhere Yellow
Acrylic Painting - Somewhere Yellow
 
Responsive Web Design: How to maximise your content for devices that haven't ...
Responsive Web Design: How to maximise your content for devices that haven't ...Responsive Web Design: How to maximise your content for devices that haven't ...
Responsive Web Design: How to maximise your content for devices that haven't ...
 
Aantal klachten van asielzoekers in België verdrievoudigd op jaar tijd
Aantal klachten van asielzoekers in België verdrievoudigd op jaar tijdAantal klachten van asielzoekers in België verdrievoudigd op jaar tijd
Aantal klachten van asielzoekers in België verdrievoudigd op jaar tijd
 
Big data analytic platform
Big data analytic platformBig data analytic platform
Big data analytic platform
 
Responsive Design & Prototyping -- An Agency Model (Part 3/3)
Responsive Design & Prototyping -- An Agency Model (Part 3/3)Responsive Design & Prototyping -- An Agency Model (Part 3/3)
Responsive Design & Prototyping -- An Agency Model (Part 3/3)
 
Leveraging Social Media to Drive B2B Influence
Leveraging Social Media to Drive B2B InfluenceLeveraging Social Media to Drive B2B Influence
Leveraging Social Media to Drive B2B Influence
 
Auto force snow 2016
Auto force snow 2016Auto force snow 2016
Auto force snow 2016
 
Fra gode intensjoner til flere donasjoner / Fundraisingkonferansen 2013
Fra gode intensjoner til flere donasjoner / Fundraisingkonferansen 2013Fra gode intensjoner til flere donasjoner / Fundraisingkonferansen 2013
Fra gode intensjoner til flere donasjoner / Fundraisingkonferansen 2013
 

Similaire à Routing 1, Season 1

Learning to code for startup mvp session 3
Learning to code for startup mvp session 3Learning to code for startup mvp session 3
Learning to code for startup mvp session 3
Henry S
 

Similaire à Routing 1, Season 1 (20)

Routing 2, Season 1
Routing 2, Season 1Routing 2, Season 1
Routing 2, Season 1
 
Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2
 
Action Controller Overview, Season 1
Action Controller Overview, Season 1Action Controller Overview, Season 1
Action Controller Overview, Season 1
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à Ruby
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Rest And Rails
Rest And RailsRest And Rails
Rest And Rails
 
Rails and the Apache SOLR Search Engine
Rails and the Apache SOLR Search EngineRails and the Apache SOLR Search Engine
Rails and the Apache SOLR Search Engine
 
Learning to code for startup mvp session 3
Learning to code for startup mvp session 3Learning to code for startup mvp session 3
Learning to code for startup mvp session 3
 
Getting started with Rails (1), Season 2
Getting started with Rails (1), Season 2Getting started with Rails (1), Season 2
Getting started with Rails (1), Season 2
 
Rails 3 - The Developers Conference - 21aug2010
Rails 3 - The Developers Conference - 21aug2010Rails 3 - The Developers Conference - 21aug2010
Rails 3 - The Developers Conference - 21aug2010
 
BEAR (Suday) design
BEAR (Suday) designBEAR (Suday) design
BEAR (Suday) design
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with Rails
 
Getting started with Rails (3), Season 2
Getting started with Rails (3), Season 2Getting started with Rails (3), Season 2
Getting started with Rails (3), Season 2
 
Active Record Form Helpers, Season 1
Active Record Form Helpers, Season 1Active Record Form Helpers, Season 1
Active Record Form Helpers, Season 1
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
Women Who Code - RSpec JSON API Workshop
Women Who Code - RSpec JSON API WorkshopWomen Who Code - RSpec JSON API Workshop
Women Who Code - RSpec JSON API Workshop
 
Getting started with DSpace 7 REST API
Getting started with DSpace 7 REST APIGetting started with DSpace 7 REST API
Getting started with DSpace 7 REST API
 
routes.rb をもう一度考えてみた #shibuyarb
routes.rb をもう一度考えてみた #shibuyarbroutes.rb をもう一度考えてみた #shibuyarb
routes.rb をもう一度考えてみた #shibuyarb
 

Plus de RORLAB

Active Support Core Extension (3)
Active Support Core Extension (3)Active Support Core Extension (3)
Active Support Core Extension (3)
RORLAB
 
Active Support Core Extension (2)
Active Support Core Extension (2)Active Support Core Extension (2)
Active Support Core Extension (2)
RORLAB
 
Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2
RORLAB
 
ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2
RORLAB
 
Active Record Query Interface (1), Season 2
Active Record Query Interface (1), Season 2Active Record Query Interface (1), Season 2
Active Record Query Interface (1), Season 2
RORLAB
 

Plus de RORLAB (20)

Getting Started with Rails (4)
Getting Started with Rails (4) Getting Started with Rails (4)
Getting Started with Rails (4)
 
Getting Started with Rails (3)
Getting Started with Rails (3) Getting Started with Rails (3)
Getting Started with Rails (3)
 
Getting Started with Rails (2)
Getting Started with Rails (2)Getting Started with Rails (2)
Getting Started with Rails (2)
 
Getting Started with Rails (1)
Getting Started with Rails (1)Getting Started with Rails (1)
Getting Started with Rails (1)
 
Self join in active record association
Self join in active record associationSelf join in active record association
Self join in active record association
 
Asset Pipeline in Ruby on Rails
Asset Pipeline in Ruby on RailsAsset Pipeline in Ruby on Rails
Asset Pipeline in Ruby on Rails
 
레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개
레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개
레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개
 
Active Support Core Extension (3)
Active Support Core Extension (3)Active Support Core Extension (3)
Active Support Core Extension (3)
 
Active Support Core Extension (2)
Active Support Core Extension (2)Active Support Core Extension (2)
Active Support Core Extension (2)
 
Active Support Core Extensions (1)
Active Support Core Extensions (1)Active Support Core Extensions (1)
Active Support Core Extensions (1)
 
Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2Action View Form Helpers - 2, Season 2
Action View Form Helpers - 2, Season 2
 
ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2
 
Active Record Query Interface (1), Season 2
Active Record Query Interface (1), Season 2Active Record Query Interface (1), Season 2
Active Record Query Interface (1), Season 2
 
Active Record Association (2), Season 2
Active Record Association (2), Season 2Active Record Association (2), Season 2
Active Record Association (2), Season 2
 
ActiveRecord Association (1), Season 2
ActiveRecord Association (1), Season 2ActiveRecord Association (1), Season 2
ActiveRecord Association (1), Season 2
 
ActiveRecord Callbacks & Observers, Season 2
ActiveRecord Callbacks & Observers, Season 2ActiveRecord Callbacks & Observers, Season 2
ActiveRecord Callbacks & Observers, Season 2
 
ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2
 
Rails Database Migration, Season 2
Rails Database Migration, Season 2Rails Database Migration, Season 2
Rails Database Migration, Season 2
 
Getting started with Rails (4), Season 2
Getting started with Rails (4), Season 2Getting started with Rails (4), Season 2
Getting started with Rails (4), Season 2
 
ActiveRecord Query Interface (1), Season 1
ActiveRecord Query Interface (1), Season 1ActiveRecord Query Interface (1), Season 1
ActiveRecord Query Interface (1), Season 1
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Routing 1, Season 1

  • 1. The 13th Round of ROR Lab. Rails Routing from the Outside In (1) May 26th, 2012 Hyoseong Choi ROR Lab.
  • 2. Rails Router http://blog.org _path _url A Controller Action ROR Lab.
  • 3. $ rake routes posts GET /posts(.:format) posts#index POST /posts(.:format) posts#create new_post GET /posts/new(.:format) posts#new edit_post GET /posts/:id/edit(.:format) posts#edit post GET /posts/:id(.:format) posts#show PUT /posts/:id(.:format) posts#update DELETE /posts/:id(.:format) posts#destroy ROR Lab.
  • 4. An Incoming Request GET /posts/17 ? ROR Lab.
  • 5. Generating paths & URLs @patient = Patient.find(17) <%= link_to "Patient Record", patient_path(@patient) %> URL = host + port + PATH ROR Lab.
  • 6. Resource Routing • Action 7 brothers • index / show / new / edit create / update / destroy in config/routes.rb resources :photos “sine” - show, index, new, edit ROR Lab.
  • 7. An Incoming Request DELETE /posts/17 ? ROR Lab.
  • 8. HTTP verbs new create C • POST R • GET index show URL • PUT update U • DELETE destroy D Note : routing orders ROR Lab.
  • 9. Multiple Resources resources :photos resources :books resources :videos resources :photos, :books, :videos ROR Lab.
  • 10. Singular Resources match "profile" => "users#show" resource :geocoder ROR Lab.
  • 11. Singular Resources resource :geocoder Action 6 brothers no index action ROR Lab.
  • 12. Controller Namespacing Admin:: module prefix namespace :admin do   resources :posts, :comments scope :module => "admin" do   resources :posts, :comments scope "/admin" do   resources :posts, :comments ROR Lab.
  • 13. Controller Namespacing namespace :admin do   resources :posts, :comments Admin:: module prefix ROR Lab.
  • 14. Controller Namespacing scope :module => "admin" do   resources :posts, :comments Admin:: module prefix ROR Lab.
  • 15. Controller Namespacing scope "/admin" do   resources :posts, :comments without Admin:: module prefix ROR Lab.
  • 16. Nested Resources class Magazine < ActiveRecord::Base   has_many :ads end   class Ad < ActiveRecord::Base   belongs_to :magazine resources :magazines do   resources :ads ROR Lab.
  • 17. Nested Resources resources :magazines do   resources :ads ROR Lab.
  • 18. Paths & URLs From Objects <%= link_to "Ad details", magazine_ad_path(@magazine, @ad) %> <%= link_to "Ad details", url_for([@magazine, @ad]) %> <%= link_to "Ad details", [@magazine, @ad] %> ROR Lab.
  • 19. More RESTful Actions • Member Routes resources :photos do   member do     get 'preview'   end URL : /photos/1/preview with GET Named Routes : preview_photo_url and preview_photo_path ROR Lab.
  • 20. More RESTful Actions • Collection Routes resources :photos do   collection do     get 'search'   end URL : /photos/search with GET Named Routes : search_photos_url and search_photos_path ROR Lab.
  • 22.   ROR Lab.

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n