私はリソースルートメソッドが非常に便利だとわかりますが、create
とdestroy
パスヘルパーは作成されません。"Create"ルートパスヘルパー
私は
<% form_for(@object) %>
を書くことは、自動的にルート名を取得することになって、そして我々は、彼らが存在する場合、自動的に名前空間/プレフィックスを取得するために、配列や記号で遊ぶことができますが、私は多くのルートを持っていることをされていることを理解します複雑scope
の定義を取得することができませんcreate_xxx
ヘルパーは完全に私を悩ます
書くより簡単な解決策はありませんか? (私はヘルパーを生成している間、デフォルトのRESTful URLを維持しようとしています)
complicated_scope do
resources :my_resources, except: [:create, :destroy] do
post '', on: :collection, action: :create, as: 'create' # plus this generates a pluralized version, not very intuitive `create_complicated_scope_my_resourceS_path`
delete '', on: :member, action: :destroy, as: 'destroy'
end
end
EDIT。 「多少複雑スコープ」
# Company access routes under /company/
namespace :company do
# I need a company id for all nested controllers (this is NOT a resource strictly speaking, and using resources :companies, only: [] with 'on: :collection' doesn't generate appropriate urls)
scope ':company_id' do
# Company administrators
namespace :admin do
# There is a lot of stuff they can do, not just administration
namespace :administration do
# There are several parameters grouped in different controllers
resources :some_administrations do
... # finally RESTful actions and others here
end
end
end
end
end
あなたはどのような種類の複雑な範囲を扱っているのですか?私は複雑な範囲がおそらくにおいであると思うでしょう。あなたが 'create_xxx'ヘルパーを探すことによって回避するのではなく、ルーティングを単純化できるかどうか調べる価値があります。 – Nick