Search code examples
ruby-on-rails-3rails-for-zombies

Rails for Zombies Level 5 Challenge 5


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

the resources are Resources

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

my solution is

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 that i get in both cases is

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

What am i doing wrong??


Solution

  • Try this:

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