[Rails Level 1] ROUTE -- Ex

RESOURCE ROUTE

config/routes.rb

Create a resources route for zombies.

TwitterForZombies::Application.routes.draw do
  resources :zombies
end

 

ROUTE MATCHING

Create a custom route so that '/undead' will go to the undead action on the ZombiesController.

TwitterForZombies::Application.routes.draw do
  resources :zombies
  get '/undead' => 'zombies#undead'
end

 

ROUTE REDIRECTING

Create a redirect for '/undead' to '/zombies'.

TwitterForZombies::Application.routes.draw do
  resources :zombies
  get '/undead' => redirect('/zombies')
end

 

ROOT ROUTE

Create a root route to the ZombiesController index action.

TwitterForZombies::Application.routes.draw do
  resources :zombies
  get '/' => "zombies#index"
end

 

NAMED ROUTE

Create a named route. It should generate a path like '/zombies/:name' where :nameis a parameter, and points to the index action in ZombiesController. Name the route'graveyard'

TwitterForZombies::Application.routes.draw do
  get '/zombies/:name', to: 'zombies#index', :as => 'graveyard'
end

 

posted @ 2014-09-16 16:23  Zhentiw  阅读(333)  评论(0)    收藏  举报