Given Rails 4.1, two controllers CRM::CompaniesController
and CRM::ContactPeople
, two models CRM::Company
and CRM::ContactPerson
and the following routes:
namespace :crm do
resources :companies do
resources :contact_people
end
end
The generated URL helpers contain the CRM namespace only once, which is exactly what I want:
crm_company_contact_people GET /crm/companies/:company_id/contact_people(.:format)
new_crm_company_contact_person GET /crm/companies/:company_id/contact_people/new(.:format)
# ...
However, using the Array approach for URL helpers
= form_for([@crm_company, @crm_contact_person]) do |f|
tries to generate a URL with each resource namespaced:
undefined method `crm_company_crm_contact_people_path' for #<#<Class...
I would like to have "crm" in my paths only once at the beginning (unless it breaks a common Rails approach) and it would be ugly to add the URL to each form explicitly. Is there something I can do (perhaps in the routes, the model or the first form_for argument) so that Rails knows how to build the correct path? Or is there a more Rails-like way to generate this kind of structure so that Rails knows automatically how to build the paths?