2008-10-08 4 views
3

레일스 자원 라우팅의 기본 세그먼트 이름

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

의 행을 따라 레일 어플리케이션에서 경로를 만들고 싶습니다. 팬더, 호랑이 및 개는 모두 동물의 클래스에 대한 permalinks입니다.

을 수행하는 일반적인 방법

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

의 선을 따라 경로를 만듭니다.하지만 항상 같기 때문에 첫 번째 세그먼트는 필요 없습니다.

수동 라우팅을 통해이 작업을 수행 할 수 있음을 알고 있지만 레일스 리소스 사용법을 알고 싶습니다. 동물 및 블로그를 사용하는 것이 필요합니다.

답변

1

당신은이 플러그인을 사용할 수 있습니다.

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"}