我有我的视图文件夹的这种结构(它们显示logis结构):
所以我在admin子文件夹中有子文件夹,在目录文件夹中我必须子文件夹,制造商等(制造商和其他有控制器的视图,只有目录和是空的)
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
制造商,型号,类型工作正常,但文章工作奇怪…当我尝试写这样的形式部分:
= 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"
事情很糟糕,我知道
用于#<#:0xbbedf60>的未定义方法`admin_catalogs_to_manufacturers_models_types_to_articles_path’
但是例如在类型中我有这样的形式:
= form_for [:admin,@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"
解决方法
如果你想坚持这个嵌套结构,我认为最好使用嵌套资源而不是命名空间.
嵌套资源看起来像:
namespace :admin do resources :catalogs do resources :to do resources :manufacturers do resources :models do resources :types do resources :articles do
文章的形式如下:form_for [:admin,@ catalogue,@ to,@ makeufacturer,@ model,@ type,@ article]
afticles索引的url看起来像admin_catalogs_to_manufacturers_models_types_articles_path(@catalogue,@ type),并生成如下网址:www.example.com/admin/catalogs/1/to/1/制造商/ 1 /模型/ 1 /类型/ 1 /篇
请注意,url的所有部分实际上都是除admin之外的实例