【问题标题】:Rails3 Routing error. No route matches {:action=>"destroy"Rails3 路由错误。没有路线匹配 {:action=>"destroy"
【发布时间】:2011-04-14 22:48:49
【问题描述】:

我正在关注http://guides.rubyonrails.org/getting_started.html 的指南

红宝石 1.9.2p0
Rails 3.0.0

但是当我尝试添加时,我被锁定在 6.2/6.3;

我收到错误消息(我将 Post 示例切换为 Specie);

Home#index 中的 ActionController::RoutingError 没有路线匹配 {:action=>"destroy", :controller=>"species"}

终端历史:

捆绑安装
耙分贝:创建
rails 生成控制器主页索引
rm public/index.html
rails 生成脚手架 Specie name:string latin:string
耙分贝:迁移

路径 localhost:3000/species/ 有效,但 localhost:3000/species/new 无效

耙路线:

species_index GET /species(.:format) {:action=>"index", :controller=>"species"}
物种索引 POST /species(.:format) {:action=>"create", :controller=>"species"}
new_species GET /species/new(.:format) {:action=>"new", :controller=>"species"}
edit_species GET /species/:id/edit(.:format) {:action=>"edit", :controller=>"species"}
物种 GET /species/:id(.:format) {:action=>"show", :controller=>"species"}
物种 PUT /species/:id(.:format) {:action=>"update", :controller=>"species"}
物种删除 /species/:id(.:format) {:action=>"destroy", :controller=>"species"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root /(.:format) {:controller=>"home", :action=>"index"}

routes.rb

资源:物种
获取“主页/索引”
根 :to => "home#index"

【问题讨论】:

    标签: ruby ruby-on-rails-3


    【解决方案1】:

    您的问题是species 的复数形式是species(它们是相同的)。

    答案在您的rake routes 中。请注意,您将要使用:

    <%= link_to "All Species", species_index_path %>
    

    有关详细信息,请参阅路由指南中的 Section 4.8 - Overriding The Singular Form。

    【讨论】:

    • 感谢您抽出宝贵时间,非常感谢。
    猜你喜欢
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    相关资源
    最近更新 更多