我有这样定义的路线:
namespace :dealer, path: '' do
resources :images, except: :index do
resources :comments, only: [:create, :destroy] do
resources :attachments, only: :show
end
end
end
在我的视图中,使用link_to url_for([@image, comment])
会生成名为“
dealer_image_dealer_comment_path
不存在。它应该是dealer_image_comment_path
。有什么方法可以避免双重命名空间?
我收到此错误:
undefined method `dealer_image_dealer_comment_path' for #<#<Class:0x007fb599499520>:0x007fb5994980d0>
Did you mean? dealer_image_comments_path
dealer_image_comment_path
rake routes:
dealer_image_comments POST /images/:image_id/comments(.:format) dealer/comments#create {:subdomain=>"dealer"}
dealer_image_comment DELETE /images/:image_id/comments/:id(.:format) dealer/comments#destroy {:subdomain=>"dealer"}
答案 0 :(得分:0)
答案 1 :(得分:0)
我最终写了自己的帮助来完成这个:
def path_gen(namespace, models)
path = ''
models.compact!.each do |m|
path = path + '_' + m.class.name.demodulize.downcase
end
send("#{namespace}#{path}_path", *models)
end
接受path_gen([@image, comment])