Rails subfolder routing

I have this structure of my view folders (they display the logis structure):

dir

so I have a subfolder in the admin subfolder, that in the directories folder I have a subfolder, manufacturer, etc. (the manufacturer and the other have a controller with views, only directories and empty)

and the rails automatically generated the following routes for me:

namespace :admin do namespace :catalogs do namespace :to do namespace :manufacturers do namespace :models do namespace :types do resources :articles end end end end end end namespace :admin do namespace :catalogs do namespace :to do namespace :manufacturers do namespace :models do resources :types end end end end end namespace :admin do namespace :catalogs do namespace :to do namespace :manufacturers do resources :models end end end end namespace :admin do namespace :catalogs do namespace :to do resources :manufacturers end end end 

manufacturers, models, types work fine, but the articles work weird ... When I try to write this form partially:

 = form_for [:admin, :catalogs, :to, :manufacturers, :models, :types, @art] do |f| = f.label "OEM" = f.text_field :oem_number = f.label "" = f.text_field :manufacturer = f.label "" = f.text_area :name = f.label "-" = f.text_field :quantity = f.label "" = f.text_area :details = f.label "  VIN" = f.check_box :only_with_vin = f.hidden_field :type_id, @type_id .form-actions = f.submit ' ', :class => "btn btn-primary" 

something bad, I get the undefined method `admin_catalogs_to_manufacturers_models_types_to_articles_path 'for # <#: 0xbbedf60>

but, for example, in types I have this form:

 = form_for [:admin, :catalogs, :to, :manufacturers, :models, @man] do |f| %b = @man.Name %br = @man.TYP_PCON_START.to_s[4...6].concat("-").concat(@man.TYP_PCON_START.to_s[0...4]) \- -if @man.TYP_PCON_END.blank? = ". " -else = @man.TYP_PCON_END.to_s[4...6].concat("-").concat(@man.TYP_PCON_END.to_s[0...4]) %br = ((@man.TYP_HP_FROM.to_f*0.74).round).to_i kW = f.label "   ?" = f.check_box :is_in_to .form-actions = f.submit '', :class => "btn btn-danger" = link_to '', :back, :class => "btn" 

and all right, what's wrong with the articles? How and what to change on my route and optimize it? I try a little, but I get errors ...

+8
ruby-on-rails routing
source share
1 answer

If you want to keep this nested structure, I think it is better to use nested resources instead of namespaces.

Nested resources will look like this:

 namespace :admin do resources :catalogs do resources :to do resources :manufacturers do resources :models do resources :types do resources :articles do 

The article form will look like this: form_for [:admin, @catalogue, @to, @manufacturer, @model, @type, @article] URL for the arithmetic index will look like admin_catalogs_to_manufacturers_models_types_articles_path(@catalogue, @to, @manufacturer, @model, @type) and will generate a url like: www.example.com/admin/catalogs/1/to/1/manufacturer/1/model/1/type/1/articles

Please note that all parts of the URL are instances except admin

+1
source share

All Articles