Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
dffd9204
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
dffd9204
编写于
7月 25, 2011
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2252 from thedarkone/polymorphic-url-helpers
Make polymorphic_url calls go through application helpers again.
上级
02691d35
036f7757
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
9 deletion
+33
-9
actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
+1
-8
actionpack/test/dispatch/prefix_generation_test.rb
actionpack/test/dispatch/prefix_generation_test.rb
+12
-0
actionpack/test/template/test_test.rb
actionpack/test/template/test_test.rb
+1
-1
railties/test/railties/mounted_engine_test.rb
railties/test/railties/mounted_engine_test.rb
+19
-0
未找到文件。
actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
浏览文件 @
dffd9204
...
...
@@ -124,14 +124,7 @@ def polymorphic_url(record_or_hash_or_array, options = {})
args
.
last
.
kind_of?
(
Hash
)
?
args
.
last
.
merge!
(
url_options
)
:
args
<<
url_options
end
if
proxy
proxy
.
send
(
named_route
,
*
args
)
else
# we need to use url_for, because polymorphic_url can be used in context of other than
# current routes (e.g. engine's routes). As named routes from engine are not included
# calling engine's named route directly would fail.
url_for
_routes
.
url_helpers
.
__send__
(
"hash_for_
#{
named_route
}
"
,
*
args
)
end
(
proxy
||
self
).
send
(
named_route
,
*
args
)
end
# Returns the path component of a URL for the given record. It uses
...
...
actionpack/test/dispatch/prefix_generation_test.rb
浏览文件 @
dffd9204
...
...
@@ -50,7 +50,9 @@ def self.routes
scope
"/:omg"
,
:omg
=>
"awesome"
do
mount
BlogEngine
=>
"/blog"
,
:as
=>
"blog_engine"
end
match
"/posts/:id"
,
:to
=>
"outside_engine_generating#post"
,
:as
=>
:post
match
"/generate"
,
:to
=>
"outside_engine_generating#index"
match
"/polymorphic_path_for_app"
,
:to
=>
"outside_engine_generating#polymorphic_path_for_app"
match
"/polymorphic_path_for_engine"
,
:to
=>
"outside_engine_generating#polymorphic_path_for_engine"
match
"/polymorphic_with_url_for"
,
:to
=>
"outside_engine_generating#polymorphic_with_url_for"
match
"/conflicting_url"
,
:to
=>
"outside_engine_generating#conflicting"
...
...
@@ -101,6 +103,7 @@ def conflicting
class
::
OutsideEngineGeneratingController
<
ActionController
::
Base
include
BlogEngine
.
routes
.
mounted_helpers
include
RailsApplication
.
routes
.
url_helpers
def
index
render
:text
=>
blog_engine
.
post_path
(
:id
=>
1
)
...
...
@@ -110,6 +113,10 @@ def polymorphic_path_for_engine
render
:text
=>
blog_engine
.
polymorphic_path
(
Post
.
new
)
end
def
polymorphic_path_for_app
render
:text
=>
polymorphic_path
(
Post
.
new
)
end
def
polymorphic_with_url_for
render
:text
=>
blog_engine
.
url_for
(
Post
.
new
)
end
...
...
@@ -201,6 +208,11 @@ def setup
assert_equal
"/awesome/blog/posts/1"
,
last_response
.
body
end
test
"polymorphic_path_for_app"
do
get
"/polymorphic_path_for_app"
assert_equal
"/posts/1"
,
last_response
.
body
end
test
"[APP] generating engine's url with url_for(@post)"
do
get
"/polymorphic_with_url_for"
assert_equal
"http://example.org/awesome/blog/posts/1"
,
last_response
.
body
...
...
actionpack/test/template/test_test.rb
浏览文件 @
dffd9204
...
...
@@ -39,7 +39,7 @@ def test_link_to_person
with_test_route_set
do
person
=
mock
(
:name
=>
"David"
)
person
.
class
.
extend
ActiveModel
::
Naming
_routes
.
url_helpers
.
expects
(
:hash_for_
mocha_mock_path
).
with
(
person
).
returns
(
"/people/1"
)
expects
(
:
mocha_mock_path
).
with
(
person
).
returns
(
"/people/1"
)
assert_equal
'<a href="/people/1">David</a>'
,
link_to_person
(
person
)
end
end
...
...
railties/test/railties/mounted_engine_test.rb
浏览文件 @
dffd9204
...
...
@@ -15,10 +15,12 @@ def setup
app_file
'config/routes.rb'
,
<<-
RUBY
AppTemplate::Application.routes.draw do
resources :posts
match "/engine_route" => "application_generating#engine_route"
match "/engine_route_in_view" => "application_generating#engine_route_in_view"
match "/url_for_engine_route" => "application_generating#url_for_engine_route"
match "/polymorphic_route" => "application_generating#polymorphic_route"
match "/application_polymorphic_path" => "application_generating#application_polymorphic_path"
scope "/:user", :user => "anonymous" do
mount Blog::Engine => "/blog"
end
...
...
@@ -59,6 +61,7 @@ class Engine < ::Rails::Engine
resources :posts
match '/generate_application_route', :to => 'posts#generate_application_route'
match '/application_route_in_view', :to => 'posts#application_route_in_view'
match '/engine_polymorphic_path', :to => 'posts#engine_polymorphic_path'
end
RUBY
...
...
@@ -79,6 +82,10 @@ def generate_application_route
def application_route_in_view
render :inline => "<%= main_app.root_path %>"
end
def engine_polymorphic_path
render :text => polymorphic_path(Post.new)
end
end
end
RUBY
...
...
@@ -100,6 +107,10 @@ def url_for_engine_route
def polymorphic_route
render :text => polymorphic_url([blog, Blog::Post.new])
end
def application_polymorphic_path
render :text => polymorphic_path(Blog::Post.new)
end
end
RUBY
...
...
@@ -172,6 +183,14 @@ def script_name(script_name)
# test polymorphic routes
get
"/polymorphic_route"
assert_equal
"http://example.org/anonymous/blog/posts/44"
,
last_response
.
body
# test that correct path is generated for the same polymorphic_path call in an engine
get
"/somone/blog/engine_polymorphic_path"
assert_equal
"/somone/blog/posts/44"
,
last_response
.
body
# and in an application
get
"/application_polymorphic_path"
assert_equal
"/posts/44"
,
last_response
.
body
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录