Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6bb4ad38
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,发现更多精彩内容 >>
提交
6bb4ad38
编写于
12月 20, 2011
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4033 from nashby/date-helper-field-error-proc
add failing tests for issue #3487
上级
7ab47751
92088131
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
12 deletion
+35
-12
actionpack/lib/action_view/helpers/active_model_helper.rb
actionpack/lib/action_view/helpers/active_model_helper.rb
+0
-5
actionpack/lib/action_view/helpers/date_helper.rb
actionpack/lib/action_view/helpers/date_helper.rb
+9
-5
actionpack/lib/action_view/helpers/form_helper.rb
actionpack/lib/action_view/helpers/form_helper.rb
+2
-1
actionpack/test/template/active_model_helper_test.rb
actionpack/test/template/active_model_helper_test.rb
+24
-1
未找到文件。
actionpack/lib/action_view/helpers/active_model_helper.rb
浏览文件 @
6bb4ad38
require
'action_view/helpers/form_helper'
require
'active_support/core_ext/class/attribute_accessors'
require
'active_support/core_ext/enumerable'
require
'active_support/core_ext/object/blank'
...
...
@@ -47,9 +46,5 @@ def tag_generate_errors?(options)
options
[
'type'
]
!=
'hidden'
end
end
class
InstanceTag
include
ActiveModelInstanceTag
end
end
end
actionpack/lib/action_view/helpers/date_helper.rb
浏览文件 @
6bb4ad38
...
...
@@ -422,7 +422,7 @@ def select_time(datetime = Time.current, options = {}, html_options = {})
end
# Returns a select tag with options for each of the seconds 0 through 59 with the current second selected.
# The <tt>datetime</tt> can be either a +Time+ or +DateTime+ object or an integer.
# The <tt>datetime</tt> can be either a +Time+ or +DateTime+ object or an integer.
# Override the field name using the <tt>:field_name</tt> option, 'second' by default.
#
# ==== Examples
...
...
@@ -448,7 +448,7 @@ def select_second(datetime, options = {}, html_options = {})
# Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected.
# Also can return a select tag with options by <tt>minute_step</tt> from 0 through 59 with the 00 minute
# selected. The <tt>datetime</tt> can be either a +Time+ or +DateTime+ object or an integer.
# selected. The <tt>datetime</tt> can be either a +Time+ or +DateTime+ object or an integer.
# Override the field name using the <tt>:field_name</tt> option, 'minute' by default.
#
# ==== Examples
...
...
@@ -473,7 +473,7 @@ def select_minute(datetime, options = {}, html_options = {})
end
# Returns a select tag with options for each of the hours 0 through 23 with the current hour selected.
# The <tt>datetime</tt> can be either a +Time+ or +DateTime+ object or an integer.
# The <tt>datetime</tt> can be either a +Time+ or +DateTime+ object or an integer.
# Override the field name using the <tt>:field_name</tt> option, 'hour' by default.
#
# ==== Examples
...
...
@@ -868,7 +868,7 @@ def build_options(selected, options = {})
tag_options
=
{
:value
=>
value
}
tag_options
[
:selected
]
=
"selected"
if
selected
==
i
text
=
options
[
:use_two_digit_numbers
]
?
sprintf
(
"%02d"
,
i
)
:
value
text
=
options
[
:ampm
]
?
AMPM_TRANSLATION
[
i
]
:
text
text
=
options
[
:ampm
]
?
AMPM_TRANSLATION
[
i
]
:
text
select_options
<<
content_tag
(
:option
,
text
,
tag_options
)
end
(
select_options
.
join
(
"
\n
"
)
+
"
\n
"
).
html_safe
...
...
@@ -974,7 +974,7 @@ def separator(type)
end
end
class
InstanceTag
#:nodoc:
module
DateHelperInstanceTag
def
to_date_select_tag
(
options
=
{},
html_options
=
{})
datetime_selector
(
options
,
html_options
).
select_date
.
html_safe
end
...
...
@@ -1030,6 +1030,10 @@ def default_datetime(options)
end
end
class
InstanceTag
#:nodoc:
include
DateHelperInstanceTag
end
class
FormBuilder
def
date_select
(
method
,
options
=
{},
html_options
=
{})
@template
.
date_select
(
@object_name
,
method
,
objectify_options
(
options
),
html_options
)
...
...
actionpack/lib/action_view/helpers/form_helper.rb
浏览文件 @
6bb4ad38
...
...
@@ -2,6 +2,7 @@
require
'action_view/helpers/date_helper'
require
'action_view/helpers/tag_helper'
require
'action_view/helpers/form_tag_helper'
require
'action_view/helpers/active_model_helper'
require
'active_support/core_ext/class/attribute'
require
'active_support/core_ext/hash/slice'
require
'active_support/core_ext/module/method_names'
...
...
@@ -963,7 +964,7 @@ def instantiate_builder(record_name, record_object, options, &block)
end
class
InstanceTag
include
Helpers
::
TagHelper
,
Helpers
::
FormTagHelper
include
Helpers
::
ActiveModelInstanceTag
,
Helpers
::
TagHelper
,
Helpers
::
FormTagHelper
attr_reader
:object
,
:method_name
,
:object_name
...
...
actionpack/test/template/active_model_helper_test.rb
浏览文件 @
6bb4ad38
...
...
@@ -4,7 +4,7 @@ class ActiveModelHelperTest < ActionView::TestCase
tests
ActionView
::
Helpers
::
ActiveModelHelper
silence_warnings
do
class
Post
<
Struct
.
new
(
:author_name
,
:body
)
class
Post
<
Struct
.
new
(
:author_name
,
:body
,
:updated_at
)
include
ActiveModel
::
Conversion
include
ActiveModel
::
Validations
...
...
@@ -20,9 +20,11 @@ def setup
@post
=
Post
.
new
@post
.
errors
[
:author_name
]
<<
"can't be empty"
@post
.
errors
[
:body
]
<<
"foo"
@post
.
errors
[
:updated_at
]
<<
"bar"
@post
.
author_name
=
""
@post
.
body
=
"Back to the hill and over it again!"
@post
.
updated_at
=
Date
.
new
(
2004
,
6
,
15
)
end
def
test_text_area_with_errors
...
...
@@ -39,6 +41,27 @@ def test_text_field_with_errors
)
end
def
test_date_select_with_errors
assert_dom_equal
(
%(<div class="field_with_errors"><select id="post_updated_at_1i" name="post[updated_at(1i)]">\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n</select>\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="15" />\n</div>)
,
date_select
(
"post"
,
"updated_at"
,
:discard_month
=>
true
,
:discard_day
=>
true
,
:start_year
=>
2004
,
:end_year
=>
2005
)
)
end
def
test_datetime_select_with_errors
assert_dom_equal
(
%(<div class="field_with_errors"><input id="post_updated_at_1i" name="post[updated_at(1i)]" type="hidden" value="2004" />\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="15" />\n<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n<option selected="selected" value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_updated_at_5i" name="post[updated_at(5i)]">\n<option selected="selected" value="00">00</option>\n</select>\n</div>)
,
datetime_select
(
"post"
,
"updated_at"
,
:discard_year
=>
true
,
:discard_month
=>
true
,
:discard_day
=>
true
,
:minute_step
=>
60
)
)
end
def
test_time_select_with_errors
assert_dom_equal
(
%(<div class="field_with_errors"><input id="post_updated_at_1i" name="post[updated_at(1i)]" type="hidden" value="2004" />\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="15" />\n<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n<option selected="selected" value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_updated_at_5i" name="post[updated_at(5i)]">\n<option selected="selected" value="00">00</option>\n</select>\n</div>)
,
time_select
(
"post"
,
"updated_at"
,
:minute_step
=>
60
)
)
end
def
test_hidden_field_does_not_render_errors
assert_dom_equal
(
%(<input id="post_author_name" name="post[author_name]" type="hidden" value="" />)
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录