Routing 2, Season 1
Upcoming SlideShare
Loading in...5
×
 

Routing 2, Season 1

on

  • 1,638 views

The 14th Round of ROR Lab.

The 14th Round of ROR Lab.

Statistics

Views

Total Views
1,638
Views on SlideShare
799
Embed Views
839

Actions

Likes
0
Downloads
3
Comments
0

9 Embeds 839

http://rorlab.org 572
http://lab.wordstory.net 188
http://www.rorlab.org 33
http://localhost 28
http://kt.rorlab.org 10
http://ror.la 3
http://webcache.googleusercontent.com 2
http://livecoding.rorlab.org 2
http://211.60.184.138 1
More...

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Routing 2, Season 1 Routing 2, Season 1 Presentation Transcript

  • The 14th Round of ROR Lab. Rails Routingfrom the Outside In (2) June 9th, 2012 Hyoseong Choi ROR Lab.
  • Non-Resourcefuldefault Rails route : match :controller(/:action(/:id)) symbols bound to parametersspecial 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 Segmentsmatch :controller/:action/:id/with_user/:user_id ROR Lab.
  • Query String/photos/show/1?user_id=2params[:controller] = “photos”params[:action] = “show”params[:id] = 1params[:user_id] = 2 ROR Lab.
  • Defining Defaultsmatch photos/:id => photos#showmatch photos/:id => photos#show, ROR Lab.
  • Naming Routesmatch exit => sessions#destroy, :as => :logoutlogout_path, logout_url ROR Lab.
  • HTTP Verbmatch photos/show => photos#show, :via => :getget photos/showmatch 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   endhttp://api.rubyonrails.org/classes/ActionDispatch/Http/URL.html ROR Lab.
  • Request object attributes ROR Lab.
  • Advanced Constraintsclass BlacklistConstraint  def initialize    @ips = Blacklist.retrieve_ips  end   def matches?(request)    @ips.include?(request.remote_ip)  endend TwitterClone::Application.routes.draw do  match "*path" => "blacklist#index",    :constraints => BlacklistConstraint.new ROR Lab.
  • Route Globbing: pattern matching using wildcard segmentsmatch 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 routematch 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 segmentsmatch *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.13.1~ match *pages => pages#show3.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.
  • Redirectionusing a 301 ‘moved permanently’ redirectmatch "/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 Applicationsmatch "/application.js" => Sprockets ROR Lab.
  • Using root “/”root :to => pages#main ROR Lab.
  • CustomizingResourceful Routesresources :photos, :controller => "images"resources :photos, :constraints => {:id => /[A-Z][A-Z][0-9]+/}orconstraints(:id => /[A-Z][A-Z][0-9]+/) do  resources :photos  resources :accountsendresources :photos, :as => "images" ROR Lab.
  • CustomizingResourceful Routesresources :photos, :controller => "images" ROR Lab.
  • CustomizingResourceful Routesresources :photos, :as => "images" ROR Lab.
  • CustomizingResourceful Routesresources :photos, :path_names => { :new => make, :edit => change }/photos/make/photos/1/changescope :path_names => { :new => "make" } do  # rest of your routesend ROR Lab.
  • CustomizingResourceful Routesscope "admin" do  resources :photos, :as => "admin_photos"end resources :photos admin_photos_path, new_admin_photo_pathscope "admin", :as => "admin" do  resources :photos, :accountsend  admin_photos_path and admin_accounts_pathresources :photos, :accounts /admin/photos and /admin/accounts ROR Lab.
  • CustomizingResourceful Routesscope ":username" do  resources :posts /bob/posts/1 params[:username] ROR Lab.
  • CustomizingResourceful Routesresources :photos, :only => [:index, :show]resources :photos, :except => :destroy ROR Lab.
  • CustomizingResourceful Routesscope(:path_names => { :new => "neu", :edit => "bearbeiten" }) do  resources :categories, :path => "kategorien"end ROR Lab.
  • CustomizingResourceful Routesresources :magazines do  resources :ads, :as => periodical_adsendmagazine_periodical_ads_urledit_magazine_periodical_ad_path ROR Lab.
  • 감사합니다.
  •    ROR Lab.