ruby-on-rails-3 – 僵尸5级挑战赛5

前端之家收集整理的这篇文章主要介绍了ruby-on-rails-3 – 僵尸5级挑战赛5前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
问题陈述是
创建命名路由.它应该生成一个类似’/ zombies /:name’的路径,其中:name是一个参数,并指向ZombiesController中的索引操作.将路线命名为“墓地”

资源是
资源

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

我的解决方案是

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

我也试过了

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

我在两种情况下得到的错误

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

我究竟做错了什么??

解决方法

试试这个:
match '/zombies/:name',:to=> 'zombies#index',:as => 'graveyard'

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

猜你在找的Ruby相关文章