Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 嵌套的命名空间资源、多态关联和路径_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 嵌套的命名空间资源、多态关联和路径

Ruby on rails 嵌套的命名空间资源、多态关联和路径,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,这是rails中的一个bug吗? 我的路线如下: namespace :admin do resources :products do resources :images end end 这将创建以下路径 admin_product_image GET /admin/products/:product_id/images/:id(.:format) admin/images#show 但是,当我尝试通过返回路径时 polymorphic_path( [ @imageable, @i

这是rails中的一个bug吗? 我的路线如下:

namespace :admin do
 resources :products do
  resources :images
 end
end
这将创建以下路径

admin_product_image GET /admin/products/:product_id/images/:id(.:format)  admin/images#show
但是,当我尝试通过返回路径时

polymorphic_path( [ @imageable, @image ] ) 
它返回一个错误:未定义的方法“admin\u product\u admin\u image\u path”#

它似乎在寻找“admin\u product\u admin\u image\u path”而不是“admin\u product\u image\u path”

如果我调试“多态路由.rb”并修改它:

(proxy || self).send(named_route, *args)
它正在发送“admin\u product\u admin\u image\u path”并生成错误,而不是发送:

(proxy || self).send("admin_product_image_path", *args)
没有出现错误。多态路径不适用于名称空间吗

编辑 现在可以确认多态url函数不适用于名称空间

编辑 通过编辑坏主意多态路由.rb,我成功地硬编码了一个修复坏主意

In def build_named_route_call(records, inflection, options = {}) ....
   ....
   route << model_name_from_record_or_class(record).singular_route_key
   .....
   route << model_name_from_record_or_class(record).route_key
在def build_named_route_调用中(记录、屈折、选项={})。。。。
....

route这是rails中的一个bug。我上面问题中的编辑是修复需要去哪里。。。但是我的硬编码编辑破坏了rails中的其他东西——所以要避免它


目前唯一的解决方案是不要在rails中使用名称空间、嵌套资源和多态关联。

嘿,我刚刚检查了rails
4.0.1
,它似乎工作正常。你能证实吗?如果它对你不起作用,你能粘贴你的控制器和视图代码吗?@Lucas:我把代码改成不使用名称空间,而且我没有原始代码的副本。我试图在一个新项目中重新创建,但没有得到相同的错误,但是多态路径([@product,Admin::Image.new])返回/Admin/images,我认为它应该返回/Admin/product/1/images?正如这里所述,这是已知的限制,我没有注意到您使用的模型的名称空间
Admin:
route << model_name_from_record_or_class(record).singular_route_key.gsub(/admin_/,'').to_s
route << model_name_from_record_or_class(record).route_key.gsub(/admin_/,'').to_s