僵尸轨道 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

试试这个

match '/zombies/:name' => 'zombies#index', :as => 'graveyard'
Rails

for Zombies 已针对 Rails 4 进行了更新。已弃用匹配方法。Rails 现在需要指定要响应的 HTTP 动词(如 get)。对于更新的 Rails for Zombies 的 5 级挑战 5,这是一个可能的解决方案:

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

这项工作

对我来说
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

相关内容

  • 没有找到相关文章

最新更新