Nested resources with polymorphic associations and paths

Is this a mistake in the rails? I have the following routing:

namespace :admin do
 resources :products do
  resources :images
 end
end

which creates the next path

admin_product_image GET /admin/products/:product_id/images/:id(.:format)  admin/images#show

however, when I try to get the path back through

polymorphic_path( [ @imageable, @image ] ) 

It returns an error: undefined method is `admin_product_admin_image_path 'for # <#: 0x007ff8963f0f98>

It seems to be looking for `admin_product_admin_image_path ', not' admin_product_image_path '

If I debug "polymorphic_routes.rb" and change this:

(proxy || self).send(named_route, *args)

which sends "admin_product_admin_image_path" and generates an error in order to send more quickly:

(proxy || self).send("admin_product_image_path", *args)

An error does not occur. Polymorphic_path doesn't work with namespaces?

Edit Now we can confirm that the polyorphic_url function does not work with namespaces!

Edit polymorphic_routes.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

*

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
+3
1

. , ... - .

, , .

0

Source: https://habr.com/ru/post/1660358/


All Articles