Revision 0cdd6598
Added by Dominic Cleal almost 8 years ago
app/services/menu/item.rb | ||
---|---|---|
end
|
||
|
||
def url
|
||
add_relative_path(@url || @context.routes.url_for(url_hash.merge(:only_path=>true)))
|
||
add_relative_path(@url || @context.routes.url_for(url_hash.merge(:only_path=>true).except(:use_route)))
|
||
end
|
||
|
||
def url_hash
|
Also available in: Unified diff
fixes #15250 - ignore current controller from link_to/hash_for
When link_to generates a link on a page served from a nested controller
(e.g. foreman_example/examples) with a hash of controller/action from
our hash_for_*_path extension, it calls url_for which added the current
controller prefix to the controller name, and this wouldn't exist.
When linking to hash_for_hosts_path (`:controller => 'hosts', :action =>
'index'`), this would attempt to link to `:controller =>
'foreman_example/hosts'` instead. By returning :use_route from hash_for
as in Rails 4.1, actionpack assumes the controller name is absolute and
will not add the current controller prefix.
Rails source where relative controller is assumed by url_for if no named
route was given (the :use_route option):
https://github.com/rails/rails/blob/v4.2.6/actionpack/lib/action_dispatch/routing/route_set.rb#L695-L698
Rails 4.1 source where :use_route was always added:
https://github.com/rails/rails/blob/v4.1.14.2/actionpack/lib/action_dispatch/routing/route_set.rb#L289-L294