2016-08-10 2 views
0

Railsのルーティング - へのパラメータの追加:私は次のように定義されたいくつかのルートを持っているリソース

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

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

あなたが期待するすべての素敵なルートを作成します。 1つの警告:私は

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

にこの

/owners/orders/:id/edit 

を回すために、editルートの最後に追加のパラメータを追加したいこれを行うには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正確に正しい。それについての謝罪。しかし、これは実行可能な方向だと私は信じています。

関連する問題