2016-08-10 4 views
0

다음과 같이 내가 정의 어떤 경로를 가지고 : 당신이 기대하는 모든 좋은 경로를 생성레일 라우팅 - 매개 변수를 추가 : 자원

namespace :owners do 
    resources :orders, only: [:show, :edit, :update] do    

    resources :bibles, only: [:update] 
    end 
end 

합니다. 한 가지주의 : 나는 edit 경로의 마지막에 추가 매개 변수를 추가 할이

/owners/orders/:id/edit 

/owners/orders/:id/edit/:another_parameter 

이 작업을 수행 할 수있는 Railsy 방법은 무엇으로 전원을 켭니다?

+0

: id/edit 라우트는 주어진 id로 엔티티를 편집 중임을 의미합니다. 당신이 제안하는 것은 RESTful이 아니므로 실제로 이렇게 공식적인 방법은 없습니다. 아마도 당신은 당신이하고 싶은 것과 매개 변수가 필요한 이유에 대해 더 많은 설명을 추가 할 수있을 것입니다. – apchester

+0

추가 매개 변수는 대부분 버전 번호 역할을합니다. – opticon

+0

아마도 각 주문의 버전을 나타 내기 위해 여기에 새 모델이 필요하다고 생각합니다. 이렇게하면/owner/orders/: order_id/versions/: id/edit 행을 따라 더 전통적인 경로를 얻을 수 있습니다. RESTful 원칙에 훨씬 더 적합합니다. – apchester

답변

0

당신은 당신이

namespace :owners do 
    resources :orders, only: [:show, :update] do 
    member do 
     get 'edit/:another_parameter', to: 'orders#edit' 
    end 
    resources :bibles, only: [:update] 
    end 
end 

이것은 다음과 같은 경로 당신에게 줄 것이다 원하는 것을 달성하기 위해이 작업을 수행 할 수 있습니다

    GET /owners/orders/:id/edit/:another_parameter(.:format) owners/orders#edit 
owners_order_bible PATCH /owners/orders/:order_id/bibles/:id(.:format)  owners/bibles#update 
        PUT /owners/orders/:order_id/bibles/:id(.:format)  owners/bibles#update 
     owners_order GET /owners/orders/:id(.:format)       owners/orders#show 
        PATCH /owners/orders/:id(.:format)       owners/orders#update 
        PUT /owners/orders/:id(.:format)       owners/orders#update 
0

나는 당신이 이후 손에 라우팅 문제가 있다고 생각하지 마십시오 통화는 항상 동일한 컨트롤러로 진행됩니다. 당신이 당신의 컨트롤러,

/owners/orders/:id/edit?another_parameter=foo 

그리고이 같은 무언가를 생성해야

edit_owners_orders_path(@order, another_parameter: 'foo') 

:

나는 당신이 원하는 모든 당신이 그런 짓을 컨트롤러에 전달 된 추가 매개 변수라고 생각합니다 다음과 같은 매개 변수를 가져야합니다.

{id: 1, another_parameter: 'foo'} 

구문 중 일부는 b 정확하게 맞습니다. 그 사과. 그러나 이것이 이것이 실행 가능한 방향이라고 생각합니다.