Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a7ea06b4
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,发现更多精彩内容 >>
提交
a7ea06b4
编写于
5月 08, 2008
作者:
J
Jacek Becela
提交者:
Pratik Naik
5月 10, 2008
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make render shorthands work with namespaced controllers
Signed-off-by:
N
Pratik Naik
<
pratiknaik@gmail.com
>
上级
6776edcc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
195 addition
and
48 deletion
+195
-48
actionpack/lib/action_controller/record_identifier.rb
actionpack/lib/action_controller/record_identifier.rb
+10
-4
actionpack/lib/action_view/partials.rb
actionpack/lib/action_view/partials.rb
+2
-2
actionpack/test/activerecord/render_partial_with_record_identification_test.rb
...erecord/render_partial_with_record_identification_test.rb
+147
-42
actionpack/test/controller/record_identifier_test.rb
actionpack/test/controller/record_identifier_test.rb
+36
-0
未找到文件。
actionpack/lib/action_controller/record_identifier.rb
浏览文件 @
a7ea06b4
...
...
@@ -33,11 +33,17 @@ module RecordIdentifier
# Returns plural/singular for a record or class. Example:
#
# partial_path(post) # => "posts/post"
# partial_path(Person) # => "people/person"
def
partial_path
(
record_or_class
)
# partial_path(post) # => "posts/post"
# partial_path(Person) # => "people/person"
# partial_path(Person, "admin/games") # => "admin/people/person"
def
partial_path
(
record_or_class
,
controller_path
=
nil
)
klass
=
class_from_record_or_class
(
record_or_class
)
"
#{
klass
.
name
.
tableize
}
/
#{
klass
.
name
.
demodulize
.
underscore
}
"
if
controller_path
&&
controller_path
.
include?
(
"/"
)
"
#{
File
.
dirname
(
controller_path
)
}
/
#{
klass
.
name
.
tableize
}
/
#{
klass
.
name
.
demodulize
.
underscore
}
"
else
"
#{
klass
.
name
.
tableize
}
/
#{
klass
.
name
.
demodulize
.
underscore
}
"
end
end
# The DOM class convention is to use the singular form of an object or class. Examples:
...
...
actionpack/lib/action_view/partials.rb
浏览文件 @
a7ea06b4
...
...
@@ -119,7 +119,7 @@ def render_partial(partial_path, object_assigns = nil, local_assigns = {}) #:nod
""
end
else
render_partial
(
ActionController
::
RecordIdentifier
.
partial_path
(
partial_path
),
partial_path
,
local_assigns
)
render_partial
(
ActionController
::
RecordIdentifier
.
partial_path
(
partial_path
,
controller
.
class
.
controller_path
),
partial_path
,
local_assigns
)
end
end
...
...
@@ -147,7 +147,7 @@ def render_partial_collection_with_unknown_partial_path(collection, local_assign
templates
=
Hash
.
new
i
=
0
collection
.
map
do
|
element
|
partial_path
=
ActionController
::
RecordIdentifier
.
partial_path
(
element
)
partial_path
=
ActionController
::
RecordIdentifier
.
partial_path
(
element
,
controller
.
class
.
controller_path
)
template
=
templates
[
partial_path
]
||=
ActionView
::
PartialTemplate
.
new
(
self
,
partial_path
,
nil
,
local_assigns
)
template
.
counter
=
i
i
+=
1
...
...
actionpack/test/activerecord/render_partial_with_record_identification_test.rb
浏览文件 @
a7ea06b4
require
'active_record_unit'
class
RenderPartialWithRecordIdentificationTest
<
ActiveRecordTestCase
fixtures
:developers
,
:projects
,
:developers_projects
,
:topics
,
:replies
,
:companies
,
:mascots
class
RenderPartialWithRecordIdentificationController
<
ActionController
::
Base
def
render_with_has_many_and_belongs_to_association
@developer
=
Developer
.
find
(
1
)
render
:partial
=>
@developer
.
projects
end
class
RenderPartialWithRecordIdentificationController
<
ActionController
::
Base
def
render_with_has_many_and_belongs_to_association
@developer
=
Developer
.
find
(
1
)
render
:partial
=>
@developer
.
projects
end
def
render_with_has_many_association
@topic
=
Topic
.
find
(
1
)
render
:partial
=>
@topic
.
replies
end
def
render_with_named_scope
render
:partial
=>
Reply
.
base
end
def
render_with_has_many_through_association
@developer
=
Developer
.
find
(
:first
)
render
:partial
=>
@developer
.
topics
end
def
render_with_has_one_association
@company
=
Company
.
find
(
1
)
render
:partial
=>
@company
.
mascot
end
def
render_with_belongs_to_association
@reply
=
Reply
.
find
(
1
)
render
:partial
=>
@reply
.
topic
end
def
render_with_record
@developer
=
Developer
.
find
(
:first
)
render
:partial
=>
@developer
end
def
render_with_record_collection
@developers
=
Developer
.
find
(
:all
)
render
:partial
=>
@developers
end
def
render_with_has_many_association
@topic
=
Topic
.
find
(
1
)
render
:partial
=>
@topic
.
replies
end
def
render_with_named_scope
render
:partial
=>
Reply
.
base
end
def
render_with_has_many_through_association
@developer
=
Developer
.
find
(
:first
)
render
:partial
=>
@developer
.
topics
end
def
render_with_has_one_association
@company
=
Company
.
find
(
1
)
render
:partial
=>
@company
.
mascot
end
def
render_with_belongs_to_association
@reply
=
Reply
.
find
(
1
)
render
:partial
=>
@reply
.
topic
end
RenderPartialWithRecordIdentificationController
.
view_paths
=
[
File
.
dirname
(
__FILE__
)
+
"/../fixtures/"
]
def
render_with_record
@developer
=
Developer
.
find
(
:first
)
render
:partial
=>
@developer
end
def
render_with_record_collection
@developers
=
Developer
.
find
(
:all
)
render
:partial
=>
@developers
end
end
RenderPartialWithRecordIdentificationController
.
view_paths
=
[
File
.
dirname
(
__FILE__
)
+
"/../fixtures/"
]
class
RenderPartialWithRecordIdentificationTest
<
ActiveRecordTestCase
fixtures
:developers
,
:projects
,
:developers_projects
,
:topics
,
:replies
,
:companies
,
:mascots
def
setup
@controller
=
RenderPartialWithRecordIdentificationController
.
new
...
...
@@ -84,3 +84,108 @@ def test_rendering_partial_with_has_one_association
assert_equal
mascot
.
name
,
@response
.
body
end
end
class
RenderPartialWithRecordIdentificationController
<
ActionController
::
Base
def
render_with_has_many_and_belongs_to_association
@developer
=
Developer
.
find
(
1
)
render
:partial
=>
@developer
.
projects
end
def
render_with_has_many_association
@topic
=
Topic
.
find
(
1
)
render
:partial
=>
@topic
.
replies
end
def
render_with_has_many_through_association
@developer
=
Developer
.
find
(
:first
)
render
:partial
=>
@developer
.
topics
end
def
render_with_belongs_to_association
@reply
=
Reply
.
find
(
1
)
render
:partial
=>
@reply
.
topic
end
def
render_with_record
@developer
=
Developer
.
find
(
:first
)
render
:partial
=>
@developer
end
def
render_with_record_collection
@developers
=
Developer
.
find
(
:all
)
render
:partial
=>
@developers
end
end
RenderPartialWithRecordIdentificationController
.
view_paths
=
[
File
.
dirname
(
__FILE__
)
+
"/../fixtures/"
]
class
Game
<
Struct
.
new
(
:name
,
:id
)
def
to_param
id
.
to_s
end
end
module
Fun
class
NestedController
<
ActionController
::
Base
def
render_with_record_in_nested_controller
render
:partial
=>
Game
.
new
(
"Pong"
)
end
def
render_with_record_collection_in_nested_controller
render
:partial
=>
[
Game
.
new
(
"Pong"
),
Game
.
new
(
"Tank"
)
]
end
end
NestedController
.
view_paths
=
[
File
.
dirname
(
__FILE__
)
+
"/../fixtures/"
]
module
Serious
class
NestedDeeperController
<
ActionController
::
Base
def
render_with_record_in_deeper_nested_controller
render
:partial
=>
Game
.
new
(
"Chess"
)
end
def
render_with_record_collection_in_deeper_nested_controller
render
:partial
=>
[
Game
.
new
(
"Chess"
),
Game
.
new
(
"Sudoku"
),
Game
.
new
(
"Solitaire"
)
]
end
end
NestedDeeperController
.
view_paths
=
[
File
.
dirname
(
__FILE__
)
+
"/../fixtures/"
]
end
end
class
RenderPartialWithRecordIdentificationAndNestedControllersTest
<
ActiveRecordTestCase
def
setup
@controller
=
Fun
::
NestedController
.
new
@request
=
ActionController
::
TestRequest
.
new
@response
=
ActionController
::
TestResponse
.
new
super
end
def
test_render_with_record_in_nested_controller
get
:render_with_record_in_nested_controller
assert_template
'fun/games/_game'
end
def
test_render_with_record_collection_in_nested_controller
get
:render_with_record_collection_in_nested_controller
assert_template
'fun/games/_game'
end
end
class
RenderPartialWithRecordIdentificationAndNestedDeeperControllersTest
<
ActiveRecordTestCase
def
setup
@controller
=
Fun
::
Serious
::
NestedDeeperController
.
new
@request
=
ActionController
::
TestRequest
.
new
@response
=
ActionController
::
TestResponse
.
new
super
end
def
test_render_with_record_in_deeper_nested_controller
get
:render_with_record_in_deeper_nested_controller
assert_template
'fun/serious/games/_game'
end
def
test_render_with_record_collection_in_deeper_nested_controller
get
:render_with_record_collection_in_deeper_nested_controller
assert_template
'fun/serious/games/_game'
end
end
\ No newline at end of file
actionpack/test/controller/record_identifier_test.rb
浏览文件 @
a7ea06b4
...
...
@@ -57,6 +57,18 @@ def test_partial_path
assert_equal
expected
,
partial_path
(
Comment
)
end
def
test_partial_path_with_namespaced_controller_path
expected
=
"admin/
#{
@plural
}
/
#{
@singular
}
"
assert_equal
expected
,
partial_path
(
@record
,
"admin/posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"admin/posts"
)
end
def
test_partial_path_with_not_namespaced_controller_path
expected
=
"
#{
@plural
}
/
#{
@singular
}
"
assert_equal
expected
,
partial_path
(
@record
,
"posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"posts"
)
end
def
test_dom_class
assert_equal
@singular
,
dom_class
(
@record
)
end
...
...
@@ -100,4 +112,28 @@ def test_partial_path
assert_equal
expected
,
partial_path
(
@record
)
assert_equal
expected
,
partial_path
(
Comment
::
Nested
)
end
def
test_partial_path_with_namespaced_controller_path
expected
=
"admin/comment/nesteds/nested"
assert_equal
expected
,
partial_path
(
@record
,
"admin/posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"admin/posts"
)
end
def
test_partial_path_with_deeper_namespaced_controller_path
expected
=
"deeper/admin/comment/nesteds/nested"
assert_equal
expected
,
partial_path
(
@record
,
"deeper/admin/posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"deeper/admin/posts"
)
end
def
test_partial_path_with_even_deeper_namespaced_controller_path
expected
=
"even/more/deeper/admin/comment/nesteds/nested"
assert_equal
expected
,
partial_path
(
@record
,
"even/more/deeper/admin/posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"even/more/deeper/admin/posts"
)
end
def
test_partial_path_with_not_namespaced_controller_path
expected
=
"comment/nesteds/nested"
assert_equal
expected
,
partial_path
(
@record
,
"posts"
)
assert_equal
expected
,
partial_path
(
@klass
,
"posts"
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录