Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
32763a82
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,发现更多精彩内容 >>
提交
32763a82
编写于
3月 27, 2012
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check if the options hash already exists and merge it with the another
hash. Closes #2492 and #5615
上级
6ce0a6de
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
18 deletion
+23
-18
actionpack/lib/action_view/helpers/form_helper.rb
actionpack/lib/action_view/helpers/form_helper.rb
+2
-9
actionpack/lib/action_view/helpers/tags/label.rb
actionpack/lib/action_view/helpers/tags/label.rb
+3
-3
actionpack/test/template/form_helper_test.rb
actionpack/test/template/form_helper_test.rb
+18
-6
未找到文件。
actionpack/lib/action_view/helpers/form_helper.rb
浏览文件 @
32763a82
...
@@ -1117,17 +1117,10 @@ def fields_for(record_name, record_object = nil, fields_options = {}, &block)
...
@@ -1117,17 +1117,10 @@ def fields_for(record_name, record_object = nil, fields_options = {}, &block)
@template
.
fields_for
(
record_name
,
record_object
,
fields_options
,
&
block
)
@template
.
fields_for
(
record_name
,
record_object
,
fields_options
,
&
block
)
end
end
def
label
(
method
,
content_or_options
=
nil
,
options
=
{},
&
block
)
def
label
(
method
,
text
=
nil
,
options
=
{},
&
block
)
if
content_or_options
.
is_a?
(
Hash
)
@template
.
label
(
@object_name
,
method
,
text
,
objectify_options
(
options
),
&
block
)
content_or_options
=
objectify_options
(
content_or_options
)
else
options
=
objectify_options
(
options
)
end
@template
.
label
(
@object_name
,
method
,
content_or_options
,
options
,
&
block
)
end
end
def
check_box
(
method
,
options
=
{},
checked_value
=
"1"
,
unchecked_value
=
"0"
)
def
check_box
(
method
,
options
=
{},
checked_value
=
"1"
,
unchecked_value
=
"0"
)
@template
.
check_box
(
@object_name
,
method
,
objectify_options
(
options
),
checked_value
,
unchecked_value
)
@template
.
check_box
(
@object_name
,
method
,
objectify_options
(
options
),
checked_value
,
unchecked_value
)
end
end
...
...
actionpack/lib/action_view/helpers/tags/label.rb
浏览文件 @
32763a82
...
@@ -3,16 +3,16 @@ module Helpers
...
@@ -3,16 +3,16 @@ module Helpers
module
Tags
module
Tags
class
Label
<
Base
#:nodoc:
class
Label
<
Base
#:nodoc:
def
initialize
(
object_name
,
method_name
,
template_object
,
content_or_options
=
nil
,
options
=
nil
)
def
initialize
(
object_name
,
method_name
,
template_object
,
content_or_options
=
nil
,
options
=
nil
)
options
||=
{}
content_is_options
=
content_or_options
.
is_a?
(
Hash
)
content_is_options
=
content_or_options
.
is_a?
(
Hash
)
if
content_is_options
if
content_is_options
options
=
content_or_options
options
.
merge!
content_or_options
@content
=
nil
@content
=
nil
else
else
@content
=
content_or_options
@content
=
content_or_options
end
end
options
||=
{}
super
(
object_name
,
method_name
,
template_object
,
options
)
super
(
object_name
,
method_name
,
template_object
,
options
)
end
end
...
...
actionpack/test/template/form_helper_test.rb
浏览文件 @
32763a82
...
@@ -1046,10 +1046,24 @@ def test_form_for_with_nil_index_option_override
...
@@ -1046,10 +1046,24 @@ def test_form_for_with_nil_index_option_override
assert_dom_equal
expected
,
output_buffer
assert_dom_equal
expected
,
output_buffer
end
end
def
test_form_for_label_error_wrapping
form_for
(
@post
)
do
|
f
|
concat
f
.
label
(
:author_name
,
:class
=>
'label'
)
concat
f
.
text_field
(
:author_name
)
concat
f
.
submit
(
'Create post'
)
end
expected
=
whole_form
(
'/posts/123'
,
'edit_post_123'
,
'edit_post'
,
'patch'
)
do
"<div class='field_with_errors'><label for='post_author_name' class='label'>Author name</label></div>"
+
"<div class='field_with_errors'><input name='post[author_name]' type='text' id='post_author_name' value='' /></div>"
+
"<input name='commit' type='submit' value='Create post' />"
end
assert_dom_equal
expected
,
output_buffer
end
def
test_form_for_label_error_wrapping_without_conventional_instance_variable
def
test_form_for_label_error_wrapping_without_conventional_instance_variable
post
=
remove_instance_variable
:@post
post
=
remove_instance_variable
:@post
default_field_error_proc
=
ActionView
::
Base
.
field_error_proc
ActionView
::
Base
.
field_error_proc
=
Proc
.
new
{
|
html_tag
,
instance
|
"<div class='error'>
#{
html_tag
}
</div>"
.
html_safe
}
form_for
(
post
)
do
|
f
|
form_for
(
post
)
do
|
f
|
concat
f
.
label
(
:author_name
,
:class
=>
'label'
)
concat
f
.
label
(
:author_name
,
:class
=>
'label'
)
...
@@ -1058,14 +1072,12 @@ def test_form_for_label_error_wrapping_without_conventional_instance_variable
...
@@ -1058,14 +1072,12 @@ def test_form_for_label_error_wrapping_without_conventional_instance_variable
end
end
expected
=
whole_form
(
'/posts/123'
,
'edit_post_123'
,
'edit_post'
,
'patch'
)
do
expected
=
whole_form
(
'/posts/123'
,
'edit_post_123'
,
'edit_post'
,
'patch'
)
do
"<div class='
error
'><label for='post_author_name' class='label'>Author name</label></div>"
+
"<div class='
field_with_errors
'><label for='post_author_name' class='label'>Author name</label></div>"
+
"<div class='
error
'><input name='post[author_name]' type='text' id='post_author_name' value='' /></div>"
+
"<div class='
field_with_errors
'><input name='post[author_name]' type='text' id='post_author_name' value='' /></div>"
+
"<input name='commit' type='submit' value='Create post' />"
"<input name='commit' type='submit' value='Create post' />"
end
end
assert_dom_equal
expected
,
output_buffer
assert_dom_equal
expected
,
output_buffer
ensure
ActionView
::
Base
.
field_error_proc
=
default_field_error_proc
end
end
def
test_form_for_with_namespace
def
test_form_for_with_namespace
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录