I have such structure of my view folders (they display logis structure):
so i have subfolder in admin subfolder, that in catalogs folder i have to subfolder, manufacturer etc (manufacturer and other have there controller's with views, only catalogs and to are empty)
and rails automatically generated me such routes:
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 normally, but articles work strange... When i try to write such form partial:
= 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 is bad, i get undefined method `admin_catalogs_to_manufacturers_models_types_to_articles_path' for #<#:0xbbedf60>
but for example in types i have such 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 is ok, what's wrong with articles? How and what to change in my route and optimize it? I try a little bit, but get errors...
If you wish to hold on to this nested structure, i think it is best to use nested resources instead of namespaces.
Nested resources would look like:
namespace :admin do
resources :catalogs do
resources :to do
resources :manufacturers do
resources :models do
resources :types do
resources :articles do
A form for articles would look like: form_for [:admin, @catalogue, @to, @manufacturer, @model, @type, @article]
A url for the index of afticles would look like admin_catalogs_to_manufacturers_models_types_articles_path(@catalogue, @to, @manufacturer, @model, @type)
and would generate a url like: www.example.com/admin/catalogs/1/to/1/manufacturer/1/model/1/type/1/articles
Note that all the parts of a url are actually instances except for admin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With