Skip to content

Commit 066ce1e

Browse files
committed
Allow Engine url_helpers to respect config.relative_url_root
1 parent 6b042ad commit 066ce1e

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def define_generate_prefix(app, name)
652652

653653
script_namer = ->(options) do
654654
prefix_options = options.slice(*_route.segment_keys)
655-
prefix_options[:relative_url_root] = ""
655+
prefix_options[:script_name] = "" if options[:original_script_name]
656656

657657
if options[:_recall]
658658
prefix_options.reverse_merge!(options[:_recall].slice(*_route.segment_keys))

actionpack/lib/action_dispatch/routing/route_set.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -779,18 +779,14 @@ def generate(route_name, options, recall = {}, method_name = nil)
779779

780780
RESERVED_OPTIONS = [:host, :protocol, :port, :subdomain, :domain, :tld_length,
781781
:trailing_slash, :anchor, :params, :only_path, :script_name,
782-
:original_script_name, :relative_url_root]
782+
:original_script_name]
783783

784784
def optimize_routes_generation?
785785
default_url_options.empty?
786786
end
787787

788788
def find_script_name(options)
789-
options.delete(:script_name) || find_relative_url_root(options) || ""
790-
end
791-
792-
def find_relative_url_root(options)
793-
options.delete(:relative_url_root) || relative_url_root
789+
options.delete(:script_name) || relative_url_root || ""
794790
end
795791

796792
def path_for(options, route_name = nil, reserved = RESERVED_OPTIONS)

railties/test/railties/engine_test.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,11 @@ class Engine < ::Rails::Engine
14871487
app_file "app/controllers/bar_controller.rb", <<-RUBY
14881488
class BarController < ApplicationController
14891489
def index
1490-
render plain: bukkits.bukkit_path
1490+
text = <<~TEXT
1491+
bukkits.bukkit_path: \#{bukkits.bukkit_path}
1492+
Bukkits::Engine.routes.url_helpers.bukkit_path: \#{Bukkits::Engine.routes.url_helpers.bukkit_path}
1493+
TEXT
1494+
render plain: text
14911495
end
14921496
end
14931497
RUBY
@@ -1508,18 +1512,32 @@ def index
15081512
@plugin.write "app/controllers/bukkits/bukkit_controller.rb", <<-RUBY
15091513
class Bukkits::BukkitController < ActionController::Base
15101514
def index
1511-
render plain: main_app.bar_path
1515+
text = <<~TEXT
1516+
main_app.bar_path: \#{main_app.bar_path}
1517+
Rails.application.routes.url_helpers.bar_path: \#{Rails.application.routes.url_helpers.bar_path}
1518+
TEXT
1519+
render plain: text
15121520
end
15131521
end
15141522
RUBY
15151523

15161524
boot_rails
15171525

1526+
expected = <<~TEXT
1527+
main_app.bar_path: /foo/bar
1528+
Rails.application.routes.url_helpers.bar_path: /foo/bar
1529+
TEXT
15181530
get("/bukkits/bukkit", {}, { "SCRIPT_NAME" => "/foo" })
1519-
assert_equal "/foo/bar", last_response.body
1531+
assert_equal expected,
1532+
last_response.body
15201533

1534+
expected = <<~TEXT
1535+
bukkits.bukkit_path: /foo/bukkits/bukkit
1536+
Bukkits::Engine.routes.url_helpers.bukkit_path: /foo/bukkits/bukkit
1537+
TEXT
15211538
get("/bar", {}, { "SCRIPT_NAME" => "/foo" })
1522-
assert_equal "/foo/bukkits/bukkit", last_response.body
1539+
assert_equal expected,
1540+
last_response.body
15231541
end
15241542

15251543
test "isolated engine can be mounted under multiple static locations" do

0 commit comments

Comments
 (0)