SlideShare a Scribd company logo
1 of 29
The 14th Round of ROR Lab.


   Rails Routing
from the Outside In
         (2)
          June 9th, 2012

         Hyoseong Choi
           ROR Lab.
Non-Resourceful
default Rails route :

 match ':controller(/:action(/:id))'

               symbols bound to parameters
special symbols:
   :controller and :action

                                       ROR Lab.
Dynamic Segments
 match ':controller/:action/:id/:user_id'


 params[:id]
 params[:user_id]

When you need namespacing controllers,
 match ':controller(/:action(/:id))', :controller => /admin/[^/]+/




                                                                       ROR Lab.
Static Segments

match ':controller/:action/:id/with_user/:user_id'




                                                     ROR Lab.
Query String

/photos/show/1?user_id=2




params[:controller] = “photos”
params[:action] = “show”
params[:id] = 1
params[:user_id] = 2


                                 ROR Lab.
Defining Defaults
match 'photos/:id' => 'photos#show'




match 'photos/:id' => 'photos#show',




                                       ROR Lab.
Naming Routes

match 'exit' => 'sessions#destroy', :as => :logout




logout_path, logout_url




                                                     ROR Lab.
HTTP Verb
match 'photos/show' => 'photos#show', :via => :get




get 'photos/show'




match 'photos/show' => 'photos#show',
                 :via => [:get, :post]




                                                     ROR Lab.
Segment
             Constraints
    match 'photos/:id' => 'photos#show',




    match 'photos/:id' => 'photos#show',




X   match '/:id' => 'posts#show',




    match '/:id' => 'posts#show',
                 :constraints => { :id => /d.+/ }
    match '/:username' => 'users#show'


                                                     ROR Lab.
Request-based
                               any method on the Request object that returns aString.
     match "photos",
            :constraints => {:subdomain => "admin"}




     namespace :admin do
       constraints :subdomain => "admin" do
         resources :photos
       end




http://api.rubyonrails.org/classes/ActionDispatch/Http/URL.html


                                                                                ROR Lab.
Request object attributes




                            ROR Lab.
Advanced
         Constraints
class BlacklistConstraint
  def initialize
    @ips = Blacklist.retrieve_ips
  end
 
  def matches?(request)
    @ips.include?(request.remote_ip)
  end
end
 
TwitterClone::Application.routes.draw do
  match "*path" => "blacklist#index",
    :constraints => BlacklistConstraint.new




                                              ROR Lab.
Route Globbing
: pattern matching using wildcard segments

match 'photos/*other' => 'photos#unknown'


 • photos/12
 • /photos/long/path/to/12
 • params[:other] = “12”
 • params[:other] = “long/path/to/12”
                                            ROR Lab.
Route Globbing
             : anywhere in a route

match 'books/*section/:title' => 'books#show'




 • books/some/section/last-words-a-memoir

 • params[:section] = “some/section”
 • params[:title] = “last-words-a-memoir”
                                                ROR Lab.
Route Globbing
: even more than one wildcard segments

match '*a/foo/*b' => 'test#index'



 • zoo/woo/foo/bar/baz

 • params[:a] = “zoo/woo”
 • params[:b] = “bar/baz”
                                    ROR Lab.
Route Globbing
            : always match the optional format segment
             by defaults from Rails 3.1


3.1~    match '*pages' => 'pages#show'



3.0.x   match '*pages' => 'pages#show', :format => false
        match '*pages' => 'pages#show', :format => true


         • /foo/bar.json
         • params[:pages] = “foo/bar”
         • request format => JSON
                                                           ROR Lab.
Redirection
using a 301 ‘moved permanently’ redirect

match "/stories" => redirect("/posts")



match "/stories/:name" => redirect("/posts/%{name}")




match "/stories/:name" => redirect {|params| "/posts/
#{params[:name].pluralize}" }
match "/stories" => redirect {|p, req| "/posts/#{req.subdomain}" }




provide the leading host (http://www.example.com)

                                                                     ROR Lab.
Routing to Rack
 Applications

match "/application.js" => Sprockets




                                       ROR Lab.
Using root
            “/”

root :to => 'pages#main'




                           ROR Lab.
Customizing
Resourceful Routes
resources :photos, :controller => "images"




resources :photos, :constraints => {:id => /[A-Z][A-Z][0-9]+/}
or
constraints(:id => /[A-Z][A-Z][0-9]+/) do
  resources :photos
  resources :accounts
end




resources :photos, :as => "images"




                                                                 ROR Lab.
Customizing
Resourceful Routes
resources :photos, :controller => "images"




                                             ROR Lab.
Customizing
Resourceful Routes
resources :photos, :as => "images"




                                     ROR Lab.
Customizing
Resourceful Routes
resources :photos, :path_names => { :new => 'make', :edit => 'change' }




/photos/make
/photos/1/change




scope :path_names => { :new => "make" } do
  # rest of your routes
end




                                                                          ROR Lab.
Customizing
Resourceful Routes
scope "admin" do
  resources :photos, :as => "admin_photos"
end
 
resources :photos
                                             admin_photos_path, new_admin_photo_path




scope "admin", :as => "admin" do
  resources :photos, :accounts
end
                                             admin_photos_path and admin_accounts_path
resources :photos, :accounts
                                                 /admin/photos and /admin/accounts




                                                                                ROR Lab.
Customizing
Resourceful Routes

scope ":username" do
  resources :posts     /bob/posts/1
                       params[:username]




                                           ROR Lab.
Customizing
Resourceful Routes

resources :photos, :only => [:index, :show]
resources :photos, :except => :destroy




                                              ROR Lab.
Customizing
Resourceful Routes
scope(:path_names => { :new => "neu", :edit => "bearbeiten" }) do
  resources :categories, :path => "kategorien"
end




                                                                    ROR Lab.
Customizing
Resourceful Routes
resources :magazines do
  resources :ads, :as => 'periodical_ads'
end




magazine_periodical_ads_url

edit_magazine_periodical_ad_path




                                            ROR Lab.
감사합니다.

More Related Content

Similar to 14th Round of ROR Lab Rails Routing

Routing 1, Season 1
Routing 1, Season 1Routing 1, Season 1
Routing 1, Season 1RORLAB
 
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 2RORLAB
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Rails 3 Beautiful Code
Rails 3 Beautiful CodeRails 3 Beautiful Code
Rails 3 Beautiful CodeGreggPollack
 
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 JRubyNick Sieger
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
Rack is Spectacular
Rack is SpectacularRack is Spectacular
Rack is SpectacularBryce Kerley
 
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜崇之 清水
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2Rory Gianni
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Confneal_kemp
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js FundamentalsMark
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) RoundupWayne Carter
 

Similar to 14th Round of ROR Lab Rails Routing (20)

Routing 1, Season 1
Routing 1, Season 1Routing 1, Season 1
Routing 1, Season 1
 
Rails3 changesets
Rails3 changesetsRails3 changesets
Rails3 changesets
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
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
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Rails 3 Beautiful Code
Rails 3 Beautiful CodeRails 3 Beautiful Code
Rails 3 Beautiful Code
 
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
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Rails course day 4
Rails course day 4Rails course day 4
Rails course day 4
 
What's new in Django 1.2?
What's new in Django 1.2?What's new in Django 1.2?
What's new in Django 1.2?
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Rack is Spectacular
Rack is SpectacularRack is Spectacular
Rack is Spectacular
 
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Conf
 
Rails3 way
Rails3 wayRails3 way
Rails3 way
 
Rest And Rails
Rest And RailsRest And Rails
Rest And Rails
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) Roundup
 

More from RORLAB

Getting Started with Rails (4)
Getting Started with Rails (4) Getting Started with Rails (4)
Getting Started with Rails (4) RORLAB
 
Getting Started with Rails (3)
Getting Started with Rails (3) Getting Started with Rails (3)
Getting Started with Rails (3) RORLAB
 
Getting Started with Rails (1)
Getting Started with Rails (1)Getting Started with Rails (1)
Getting Started with Rails (1)RORLAB
 
Self join in active record association
Self join in active record associationSelf join in active record association
Self join in active record associationRORLAB
 
Asset Pipeline in Ruby on Rails
Asset Pipeline in Ruby on RailsAsset Pipeline in Ruby on Rails
Asset Pipeline in Ruby on RailsRORLAB
 
레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개
레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개
레일스가이드 한글번역 공개프로젝트 RORLabGuides 소개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 Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2RORLAB
 
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 2RORLAB
 
Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2RORLAB
 
Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2RORLAB
 
ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2RORLAB
 
Active Record Association (2), Season 2
Active Record Association (2), Season 2Active Record Association (2), Season 2
Active Record Association (2), Season 2RORLAB
 
ActiveRecord Callbacks & Observers, Season 2
ActiveRecord Callbacks & Observers, Season 2ActiveRecord Callbacks & Observers, Season 2
ActiveRecord Callbacks & Observers, Season 2RORLAB
 
ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2RORLAB
 
Rails Database Migration, Season 2
Rails Database Migration, Season 2Rails Database Migration, Season 2
Rails Database Migration, Season 2RORLAB
 
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 2RORLAB
 
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 2RORLAB
 
Action Controller Overview, Season 1
Action Controller Overview, Season 1Action Controller Overview, Season 1
Action Controller Overview, Season 1RORLAB
 

More from 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 (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)
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2
 
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
 
Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2Action View Form Helpers - 1, Season 2
Action View Form Helpers - 1, Season 2
 
Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, Season 2Layouts and Rendering in Rails, Season 2
Layouts and Rendering in Rails, 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 Association (2), Season 2
Active Record Association (2), Season 2Active Record Association (2), Season 2
Active Record Association (2), 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
 
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
 
Action Controller Overview, Season 1
Action Controller Overview, Season 1Action Controller Overview, Season 1
Action Controller Overview, Season 1
 

Recently uploaded

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Recently uploaded (20)

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

14th Round of ROR Lab Rails Routing

  • 1. The 14th Round of ROR Lab. Rails Routing from the Outside In (2) June 9th, 2012 Hyoseong Choi ROR Lab.
  • 2. Non-Resourceful default Rails route : match ':controller(/:action(/:id))' symbols bound to parameters special symbols: :controller and :action ROR Lab.
  • 3. Dynamic Segments match ':controller/:action/:id/:user_id' params[:id] params[:user_id] When you need namespacing controllers, match ':controller(/:action(/:id))', :controller => /admin/[^/]+/ ROR Lab.
  • 5. Query String /photos/show/1?user_id=2 params[:controller] = “photos” params[:action] = “show” params[:id] = 1 params[:user_id] = 2 ROR Lab.
  • 6. Defining Defaults match 'photos/:id' => 'photos#show' match 'photos/:id' => 'photos#show', ROR Lab.
  • 7. Naming Routes match 'exit' => 'sessions#destroy', :as => :logout logout_path, logout_url ROR Lab.
  • 8. HTTP Verb match 'photos/show' => 'photos#show', :via => :get get 'photos/show' match 'photos/show' => 'photos#show', :via => [:get, :post] ROR Lab.
  • 9. Segment Constraints match 'photos/:id' => 'photos#show', match 'photos/:id' => 'photos#show', X match '/:id' => 'posts#show', match '/:id' => 'posts#show', :constraints => { :id => /d.+/ } match '/:username' => 'users#show' ROR Lab.
  • 10. Request-based any method on the Request object that returns aString. match "photos", :constraints => {:subdomain => "admin"} namespace :admin do   constraints :subdomain => "admin" do     resources :photos   end http://api.rubyonrails.org/classes/ActionDispatch/Http/URL.html ROR Lab.
  • 12. Advanced Constraints class BlacklistConstraint   def initialize     @ips = Blacklist.retrieve_ips   end     def matches?(request)     @ips.include?(request.remote_ip)   end end   TwitterClone::Application.routes.draw do   match "*path" => "blacklist#index",     :constraints => BlacklistConstraint.new ROR Lab.
  • 13. Route Globbing : pattern matching using wildcard segments match 'photos/*other' => 'photos#unknown' • photos/12 • /photos/long/path/to/12 • params[:other] = “12” • params[:other] = “long/path/to/12” ROR Lab.
  • 14. Route Globbing : anywhere in a route match 'books/*section/:title' => 'books#show' • books/some/section/last-words-a-memoir • params[:section] = “some/section” • params[:title] = “last-words-a-memoir” ROR Lab.
  • 15. Route Globbing : even more than one wildcard segments match '*a/foo/*b' => 'test#index' • zoo/woo/foo/bar/baz • params[:a] = “zoo/woo” • params[:b] = “bar/baz” ROR Lab.
  • 16. Route Globbing : always match the optional format segment by defaults from Rails 3.1 3.1~ match '*pages' => 'pages#show' 3.0.x match '*pages' => 'pages#show', :format => false match '*pages' => 'pages#show', :format => true • /foo/bar.json • params[:pages] = “foo/bar” • request format => JSON ROR Lab.
  • 17. Redirection using a 301 ‘moved permanently’ redirect match "/stories" => redirect("/posts") match "/stories/:name" => redirect("/posts/%{name}") match "/stories/:name" => redirect {|params| "/posts/ #{params[:name].pluralize}" } match "/stories" => redirect {|p, req| "/posts/#{req.subdomain}" } provide the leading host (http://www.example.com) ROR Lab.
  • 18. Routing to Rack Applications match "/application.js" => Sprockets ROR Lab.
  • 19. Using root “/” root :to => 'pages#main' ROR Lab.
  • 20. Customizing Resourceful Routes resources :photos, :controller => "images" resources :photos, :constraints => {:id => /[A-Z][A-Z][0-9]+/} or constraints(:id => /[A-Z][A-Z][0-9]+/) do   resources :photos   resources :accounts end resources :photos, :as => "images" ROR Lab.
  • 21. Customizing Resourceful Routes resources :photos, :controller => "images" ROR Lab.
  • 23. Customizing Resourceful Routes resources :photos, :path_names => { :new => 'make', :edit => 'change' } /photos/make /photos/1/change scope :path_names => { :new => "make" } do   # rest of your routes end ROR Lab.
  • 24. Customizing Resourceful Routes scope "admin" do   resources :photos, :as => "admin_photos" end   resources :photos admin_photos_path, new_admin_photo_path scope "admin", :as => "admin" do   resources :photos, :accounts end   admin_photos_path and admin_accounts_path resources :photos, :accounts /admin/photos and /admin/accounts ROR Lab.
  • 25. Customizing Resourceful Routes scope ":username" do   resources :posts /bob/posts/1 params[:username] ROR Lab.
  • 26. Customizing Resourceful Routes resources :photos, :only => [:index, :show] resources :photos, :except => :destroy ROR Lab.
  • 27. Customizing Resourceful Routes scope(:path_names => { :new => "neu", :edit => "bearbeiten" }) do   resources :categories, :path => "kategorien" end ROR Lab.
  • 28. Customizing Resourceful Routes resources :magazines do   resources :ads, :as => 'periodical_ads' end magazine_periodical_ads_url edit_magazine_periodical_ad_path ROR Lab.
  • 30.   ROR Lab.

Editor's Notes

  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
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n