Screencast: Routes in Rails 3

In Rails 3 wurde das Routing angepasst und in mancher Hinsicht vereinfacht. Ryan zeigt in dieser Woche wie bestehende Routen auf das neue Schema angepasst werden können, und was die neuen Features sind.

Be Sociable, Share!
 

Download:

Download (30.2 MB, 13:31)
Alternativer Download für iPod & Apple TV (19 MB, 13:31)

 

Resourcen:

 

Quellcode:

rails detour
mate detour
rails g controller info about
rails s
Detour::Application.routes.draw do |map|
  # map.resources :products, :member => { :detailed => :get }
  resources :products do
    get :detailed, :on => :member
  end
  
  # map.resources :forums, :collection => { :sortable => :get, :sort => :put } do |forums|
  #   forums.resources :topics
  # end
  resources :forums do
    collection do
      get :sortable
      put :sort
    end
    resources :topics
  end
  
  # map.root :controller => "home", :action => "index"
  root :to => "home#index"
  
  # map.about "/about", :controller => "info", :action => "about" 
  match "/about(.:format)" => "info#about", :as => :about
  
  match "/:year(/:month(/:day))" => "info#about", :constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ }
  
  match "/secret" => "info#about", :constraints => { :user_agent => /Firefox/ }
  
  constraints :host => /localhost/ do
    match "/secret" => "info#about"
  end
  
  match "/hello" => proc { |env| [200, {}, "Hello Rack!"] }
end
<!-- info/about.html.erb -->
<%= debug params %>
Be Sociable, Share!

Eingestellt am 01.03.2010 um 10:28

Kategorie: Tutorials

Be Sociable, Share!

Kommentare für diesen Artikel wurden geschlossen.

Suchen auf rubyonrails.de

Aktuelle Rails Version + Abhängigkeiten:

Gem rails-3.0.0
actionmailer (= 3.0.0, runtime)
actionpack (= 3.0.0, runtime)
activerecord (= 3.0.0, runtime)
activeresource (= 3.0.0, runtime)
activesupport (= 3.0.0, runtime)
bundler (~> 1.0.0, runtime)
railties (= 3.0.0, runtime)

Rails auf Rubyforge
Rails auf Github