mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #2577 from rails-noob/master
Fix double slash at start of paths when mounting an engine at the root.
This commit is contained in:
commit
ef14a0ec86
2 changed files with 51 additions and 1 deletions
|
@ -452,7 +452,9 @@ module ActionDispatch
|
||||||
prefix_options = options.slice(*_route.segment_keys)
|
prefix_options = options.slice(*_route.segment_keys)
|
||||||
# we must actually delete prefix segment keys to avoid passing them to next url_for
|
# we must actually delete prefix segment keys to avoid passing them to next url_for
|
||||||
_route.segment_keys.each { |k| options.delete(k) }
|
_route.segment_keys.each { |k| options.delete(k) }
|
||||||
_routes.url_helpers.send("#{name}_path", prefix_options)
|
prefix = _routes.url_helpers.send("#{name}_path", prefix_options)
|
||||||
|
prefix = '' if prefix == '/'
|
||||||
|
prefix
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,13 +11,17 @@ module ApplicationTests
|
||||||
|
|
||||||
add_to_config("config.action_dispatch.show_exceptions = false")
|
add_to_config("config.action_dispatch.show_exceptions = false")
|
||||||
|
|
||||||
|
@simple_plugin = engine "weblog"
|
||||||
@plugin = engine "blog"
|
@plugin = engine "blog"
|
||||||
|
|
||||||
app_file 'config/routes.rb', <<-RUBY
|
app_file 'config/routes.rb', <<-RUBY
|
||||||
AppTemplate::Application.routes.draw do
|
AppTemplate::Application.routes.draw do
|
||||||
|
mount Weblog::Engine, :at => '/', :as => 'weblog'
|
||||||
resources :posts
|
resources :posts
|
||||||
match "/engine_route" => "application_generating#engine_route"
|
match "/engine_route" => "application_generating#engine_route"
|
||||||
match "/engine_route_in_view" => "application_generating#engine_route_in_view"
|
match "/engine_route_in_view" => "application_generating#engine_route_in_view"
|
||||||
|
match "/weblog_engine_route" => "application_generating#weblog_engine_route"
|
||||||
|
match "/weblog_engine_route_in_view" => "application_generating#weblog_engine_route_in_view"
|
||||||
match "/url_for_engine_route" => "application_generating#url_for_engine_route"
|
match "/url_for_engine_route" => "application_generating#url_for_engine_route"
|
||||||
match "/polymorphic_route" => "application_generating#polymorphic_route"
|
match "/polymorphic_route" => "application_generating#polymorphic_route"
|
||||||
match "/application_polymorphic_path" => "application_generating#application_polymorphic_path"
|
match "/application_polymorphic_path" => "application_generating#application_polymorphic_path"
|
||||||
|
@ -28,6 +32,29 @@ module ApplicationTests
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
|
|
||||||
|
@simple_plugin.write "lib/weblog.rb", <<-RUBY
|
||||||
|
module Weblog
|
||||||
|
class Engine < ::Rails::Engine
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
@simple_plugin.write "config/routes.rb", <<-RUBY
|
||||||
|
Weblog::Engine.routes.draw do
|
||||||
|
match '/weblog' => "weblogs#index", :as => 'weblogs'
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
@simple_plugin.write "app/controllers/weblogs_controller.rb", <<-RUBY
|
||||||
|
class WeblogsController < ActionController::Base
|
||||||
|
def index
|
||||||
|
render :text => request.url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
|
||||||
@plugin.write "app/models/blog/post.rb", <<-RUBY
|
@plugin.write "app/models/blog/post.rb", <<-RUBY
|
||||||
module Blog
|
module Blog
|
||||||
class Post
|
class Post
|
||||||
|
@ -100,6 +127,14 @@ module ApplicationTests
|
||||||
render :inline => "<%= blog.posts_path %>"
|
render :inline => "<%= blog.posts_path %>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def weblog_engine_route
|
||||||
|
render :text => weblog.weblogs_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def weblog_engine_route_in_view
|
||||||
|
render :inline => "<%= weblog.weblogs_path %>"
|
||||||
|
end
|
||||||
|
|
||||||
def url_for_engine_route
|
def url_for_engine_route
|
||||||
render :text => blog.url_for(:controller => "blog/posts", :action => "index", :user => "john", :only_path => true)
|
render :text => blog.url_for(:controller => "blog/posts", :action => "index", :user => "john", :only_path => true)
|
||||||
end
|
end
|
||||||
|
@ -192,5 +227,18 @@ module ApplicationTests
|
||||||
get "/application_polymorphic_path"
|
get "/application_polymorphic_path"
|
||||||
assert_equal "/posts/44", last_response.body
|
assert_equal "/posts/44", last_response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "route path for controller action when engine is mounted at root" do
|
||||||
|
get "/weblog_engine_route"
|
||||||
|
assert_equal "/weblog", last_response.body
|
||||||
|
|
||||||
|
get "/weblog_engine_route_in_view"
|
||||||
|
assert_equal "/weblog", last_response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
test "request url for controller action when engine is mounted at root" do
|
||||||
|
get "/weblog"
|
||||||
|
assert_equal "http://example.org/weblog", last_response.body
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue