Rails for Zombies Level 5 Challenge 5

Problem Statement Create a named route. It should generate a path, for example, '/ zombies /: name', where: name is a parameter, and indicates the action of the index in ZombiesController. Name the route "graveyard"

resources resources

zombies id name graveyard 1 Ash Glen Haven Memorial Cemetary 2 Bob Chapel Hill Cemetary 3 Jim My Fathers Basement 

My decision

 TwitterForZombies::Application.routes.draw do match ':name' => 'Zombies#index', :as => 'graveyard' end 

I also tried

 TwitterForZombies::Application.routes.draw do match ':name' => 'Zombie#index', :as => 'graveyard' end 

the error I get in both cases is

 Sorry, Try Again Did not route to ZombiesController index action with :name parameter 

What am I doing wrong?

+6
source share
4 answers

Try the following:

 match '/zombies/:name',:to=> 'zombies#index', :as => 'graveyard' RailsForZombies::Application.routes.draw do resources :zombie match '/zombies/:name',:to=> 'Zombies#index', :as => 'graveyard' end 
+8
source

try it

 match '/zombies/:name' => 'zombies#index', :as => 'graveyard' 
+8
source

Rails for Zombies has been updated for Rails 4. The matching method is deprecated. Rails now requires specifying an HTTP verb (e.g. get) to respond. For the updated Level 5 Challenge 5 Rails for Zombies, this is one of the possible solutions:

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

this work is for me

 RailsForZombies::Application.routes.draw do match 'zombies/:name' => 'Zombies#index' , :as => "graveyard" #match ':name' => 'Zombie#index', :as => 'graveyard' #match 'zombies/:name',:to=> 'zombies#index', :as => 'graveyard' end 
+1
source

Source: https://habr.com/ru/post/888306/


All Articles