ruby on rails - Implicit routing for nested controllers with same namespace -
given rails 4.1, 2 controllers crm::companiescontroller
, crm::contactpeople
, 2 models crm::company
, crm::contactperson
, following routes:
namespace :crm resources :companies resources :contact_people end end
the generated url helpers contain crm namespace once, want:
crm_company_contact_people /crm/companies/:company_id/contact_people(.:format) new_crm_company_contact_person /crm/companies/:company_id/contact_people/new(.:format) # ...
however, using array approach url helpers
= form_for([@crm_company, @crm_contact_person]) |f|
tries generate url each resource namespaced:
undefined method `crm_company_crm_contact_people_path' #<#<class...
i have "crm" in paths once @ beginning (unless breaks common rails approach) , ugly add url each form explicitly. there can (perhaps in routes, model or first form_for argument) rails knows how build correct path? or there more rails-like way generate kind of structure rails knows automatically how build paths?
you need include namespace in call form_for
:
= form_for([:crm, @crm_company, @crm_contact_person]) |f|
also, since you're using namespaced models, need define following class method on them (from rails/rails issue #10705) ignore namespace:
def self.use_relative_model_naming? true end
Comments
Post a Comment