Default segment name in rails resources routing

前端 未结 2 929
既然无缘
既然无缘 2020-12-21 06:01

I want to create a route in my rails application along the lines of

/panda/blog
/tiger/blog
/dog/blog

where panda, tiger, and dog are all p

相关标签:
2条回答
  • 2020-12-21 06:46

    In rails 3.x, you can add path => "" to any resource or resources call to remove the first segment from the generated path.

    resources :animals, :path => ""
    

    $ rake routes
    
        animals GET    /                   {:action=>"index", :controller=>"animals"}
                POST   /                   {:action=>"create", :controller=>"animals"}
     new_animal GET    /new(.:format)      {:action=>"new", :controller=>"animals"}
    edit_animal GET    /:id/edit(.:format) {:action=>"edit", :controller=>"animals"}
         animal GET    /:id(.:format)      {:action=>"show", :controller=>"animals"}
                PUT    /:id(.:format)      {:action=>"update", :controller=>"animals"}
                DELETE /:id(.:format)      {:action=>"destroy", :controller=>"animals"}
    
    0 讨论(0)
  • 2020-12-21 06:54

    You can use this plugin:

    http://github.com/caring/default_routing/tree/master

    0 讨论(0)
提交回复
热议问题