Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c2b6f63b
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,发现更多精彩内容 >>
提交
c2b6f63b
编写于
11月 17, 2011
作者:
A
Alexander Uvarov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix impractical I18n lookup in nested fields_for
上级
e3671422
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
55 addition
and
1 deletion
+55
-1
actionpack/lib/action_view/helpers/form_helper.rb
actionpack/lib/action_view/helpers/form_helper.rb
+9
-1
actionpack/test/template/form_helper_test.rb
actionpack/test/template/form_helper_test.rb
+46
-0
未找到文件。
actionpack/lib/action_view/helpers/form_helper.rb
浏览文件 @
c2b6f63b
...
...
@@ -995,8 +995,16 @@ def to_label_tag(text = nil, options = {}, &block)
label_tag
(
name_and_id
[
"id"
],
options
,
&
block
)
else
content
=
if
text
.
blank?
object_name
.
gsub!
(
/\[(.*)_attributes\]\[\d\]/
,
'.\1'
)
method_and_value
=
tag_value
.
present?
?
"
#{
method_name
}
.
#{
tag_value
}
"
:
method_name
I18n
.
t
(
"helpers.label.
#{
object_name
}
.
#{
method_and_value
}
"
,
:default
=>
""
).
presence
if
object
.
respond_to?
(
:to_model
)
key
=
object
.
class
.
model_name
.
i18n_key
i18n_default
=
[
"
#{
key
}
.
#{
method_and_value
}
"
.
to_sym
,
""
]
end
i18n_default
||=
""
I18n
.
t
(
"
#{
object_name
}
.
#{
method_and_value
}
"
,
:default
=>
i18n_default
,
:scope
=>
"helpers.label"
).
presence
else
text
.
to_s
end
...
...
actionpack/test/template/form_helper_test.rb
浏览文件 @
c2b6f63b
...
...
@@ -27,7 +27,13 @@ def setup
:body
=>
"Write entire text here"
,
:color
=>
{
:red
=>
"Rojo"
},
:comments
=>
{
:body
=>
"Write body here"
}
},
:tag
=>
{
:value
=>
"Tag"
}
}
}
...
...
@@ -68,6 +74,12 @@ def @post.to_param; '123'; end
@post
.
secret
=
1
@post
.
written_on
=
Date
.
new
(
2004
,
6
,
15
)
@post
.
comments
=
[]
@post
.
comments
<<
@comment
@post
.
tags
=
[]
@post
.
tags
<<
Tag
.
new
@blog_post
=
Blog
::
Post
.
new
(
"And his name will be forty and four."
,
44
)
end
...
...
@@ -151,6 +163,40 @@ def test_label_with_locales_and_value
I18n
.
locale
=
old_locale
end
def
test_label_with_locales_and_nested_attributes
old_locale
,
I18n
.
locale
=
I18n
.
locale
,
:label
form_for
(
@post
,
:html
=>
{
:id
=>
'create-post'
})
do
|
f
|
f
.
fields_for
(
:comments
)
do
|
cf
|
concat
cf
.
label
(
:body
)
end
end
expected
=
whole_form
(
"/posts/123"
,
"create-post"
,
"edit_post"
,
:method
=>
"put"
)
do
"<label for=
\"
post_comments_attributes_0_body
\"
>Write body here</label>"
end
assert_dom_equal
expected
,
output_buffer
ensure
I18n
.
locale
=
old_locale
end
def
test_label_with_locales_fallback_and_nested_attributes
old_locale
,
I18n
.
locale
=
I18n
.
locale
,
:label
form_for
(
@post
,
:html
=>
{
:id
=>
'create-post'
})
do
|
f
|
f
.
fields_for
(
:tags
)
do
|
cf
|
concat
cf
.
label
(
:value
)
end
end
expected
=
whole_form
(
"/posts/123"
,
"create-post"
,
"edit_post"
,
:method
=>
"put"
)
do
"<label for=
\"
post_tags_attributes_0_value
\"
>Tag</label>"
end
assert_dom_equal
expected
,
output_buffer
ensure
I18n
.
locale
=
old_locale
end
def
test_label_with_for_attribute_as_symbol
assert_dom_equal
(
'<label for="my_for">Title</label>'
,
label
(
:post
,
:title
,
nil
,
:for
=>
"my_for"
))
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录