路径助手不再自动获取对象的id?

时间:2011-11-29 09:00:03

标签: ruby-on-rails ruby-on-rails-3 routes

由于某种原因,这个不再起作用了

admin_club_path(club)

但是后续工作

admin_club_path(club.id)

任何人都知道原因是什么?

这是错误消息:

No route matches {:action=>"show", :controller=>"admin/clubs", :id=>#<Club id: 98, name: "1. FSV Mainz 05 II", image: "mainz05.gif", photo_id: 3, league_id: 5, approved: false, permalink: "1-fsv-mainz-05-ii", created_at: "2011-11-22 16:43:13", updated_at: "2011-11-22 16:43:13">}

显然它将whoe对象视为id,但为什么?

路线似乎没问题:

           admin_clubs GET        /admin/clubs(.:format) {:action=>"index", :controller=>"admin/clubs"}
                       POST       /admin/clubs(.:format) {:action=>"create", :controller=>"admin/clubs"}
        new_admin_club GET        /admin/clubs/new(.:format) {:action=>"new", :controller=>"admin/clubs"}
       edit_admin_club GET        /admin/clubs/:id/edit(.:format) {:action=>"edit", :controller=>"admin/clubs"}
            admin_club GET        /admin/clubs/:id(.:format) {:action=>"show", :controller=>"admin/clubs"}
                       PUT        /admin/clubs/:id(.:format) {:action=>"update", :controller=>"admin/clubs"}
                       DELETE     /admin/clubs/:id(.:format) {:action=>"destroy", :controller=>"admin/clubs"}
                  club GET        /clubs/:id(.:format) {:action=>"show", :controller=>"clubs"}

1 个答案:

答案 0 :(得分:1)

Lucapette给了我正确的提示。我正在使用permalink gem,它在模型中有以下内容:

permalink :name, :unique => true, :to_param => %w(id name)

删除:to_param参数后,一切正常。我会把它报告给他们的开发者宝石!

谢谢lucapette和dombesz!