Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9345a116
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 搜索 >>
提交
9345a116
编写于
7月 21, 2012
作者:
C
Carlos Galdino + Rafael Mendonça França
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add back `:confirm` and change deprecation horizon to 4.1
上级
f5d0e3d7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
144 addition
and
2 deletion
+144
-2
actionpack/CHANGELOG.md
actionpack/CHANGELOG.md
+2
-2
actionpack/lib/action_view/helpers/form_tag_helper.rb
actionpack/lib/action_view/helpers/form_tag_helper.rb
+37
-0
actionpack/lib/action_view/helpers/url_helper.rb
actionpack/lib/action_view/helpers/url_helper.rb
+19
-0
actionpack/test/template/form_tag_helper_test.rb
actionpack/test/template/form_tag_helper_test.rb
+28
-0
actionpack/test/template/url_helper_test.rb
actionpack/test/template/url_helper_test.rb
+58
-0
未找到文件。
actionpack/CHANGELOG.md
浏览文件 @
9345a116
## Rails 4.0.0 (unreleased) ##
*
Remov
e
`:confirm`
in favor of
`:data => { :confirm => "Text" }`
option for
`button_to`
,
`button_tag`
,
`image_submit_tag`
,
`link_to`
and
`submit_tag`
helpers.
*
Deprecat
e
`:confirm`
in favor of
`:data => { :confirm => "Text" }`
option for
`button_to`
,
`button_tag`
,
`image_submit_tag`
,
`link_to`
and
`submit_tag`
helpers.
*Carlos Galdino*
*Carlos Galdino
+ Rafael Mendonça França
*
*
Show routes in exception page while debugging a
`RoutingError`
in development.
*Richard Schneeman and Mattt Thompson*
...
...
actionpack/lib/action_view/helpers/form_tag_helper.rb
浏览文件 @
9345a116
...
...
@@ -386,6 +386,12 @@ def radio_button_tag(name, value, checked = false, options = {})
# * <tt>:disabled</tt> - If true, the user will not be able to use this input.
# * Any other key creates standard HTML options for the tag.
#
# ==== Data attributes
#
# * <tt>:confirm => 'question?'</tt> - If present the unobtrusive JavaScript
# drivers will provide a prompt with the question specified. If the user accepts,
# the form is processed normally, otherwise no action is taken.
#
# ==== Examples
# submit_tag
# # => <input name="commit" type="submit" value="Save changes" />
...
...
@@ -411,6 +417,12 @@ def radio_button_tag(name, value, checked = false, options = {})
def
submit_tag
(
value
=
"Save changes"
,
options
=
{})
options
=
options
.
stringify_keys
if
confirm
=
options
.
delete
(
"confirm"
)
ActiveSupport
::
Deprecation
.
warn
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead'"
options
[
"data-confirm"
]
=
confirm
end
tag
:input
,
{
"type"
=>
"submit"
,
"name"
=>
"commit"
,
"value"
=>
value
}.
update
(
options
)
end
...
...
@@ -427,6 +439,13 @@ def submit_tag(value = "Save changes", options = {})
# use this input.
# * Any other key creates standard HTML options for the tag.
#
# ==== Data attributes
#
# * <tt>:confirm => 'question?'</tt> - If present, the
# unobtrusive JavaScript drivers will provide a prompt with
# the question specified. If the user accepts, the form is
# processed normally, otherwise no action is taken.
#
# ==== Examples
# button_tag
# # => <button name="button" type="submit">Button</button>
...
...
@@ -443,6 +462,12 @@ def button_tag(content_or_options = nil, options = nil, &block)
options
||=
{}
options
=
options
.
stringify_keys
if
confirm
=
options
.
delete
(
"confirm"
)
ActiveSupport
::
Deprecation
.
warn
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead'"
options
[
"data-confirm"
]
=
confirm
end
options
.
reverse_merge!
'name'
=>
'button'
,
'type'
=>
'submit'
content_tag
:button
,
content_or_options
||
'Button'
,
options
,
&
block
...
...
@@ -457,6 +482,12 @@ def button_tag(content_or_options = nil, options = nil, &block)
# * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
# * Any other key creates standard HTML options for the tag.
#
# ==== Data attributes
#
# * <tt>:confirm => 'question?'</tt> - This will add a JavaScript confirm
# prompt with the question specified. If the user accepts, the form is
# processed normally, otherwise no action is taken.
#
# ==== Examples
# image_submit_tag("login.png")
# # => <input src="/images/login.png" type="image" />
...
...
@@ -475,6 +506,12 @@ def button_tag(content_or_options = nil, options = nil, &block)
def
image_submit_tag
(
source
,
options
=
{})
options
=
options
.
stringify_keys
if
confirm
=
options
.
delete
(
"confirm"
)
ActiveSupport
::
Deprecation
.
warn
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead'"
options
[
"data-confirm"
]
=
confirm
end
tag
:input
,
{
"type"
=>
"image"
,
"src"
=>
path_to_image
(
source
)
}.
update
(
options
)
end
...
...
actionpack/lib/action_view/helpers/url_helper.rb
浏览文件 @
9345a116
...
...
@@ -160,6 +160,12 @@ def url_for(options = nil)
# completion of the Ajax request and performing JavaScript operations once
# they're complete
#
# ==== Data attributes
#
# * <tt>:confirm => 'question?'</tt> - This will allow the unobtrusive JavaScript
# driver to prompt with the question specified. If the user accepts, the link is
# processed normally, otherwise no action is taken.
#
# ==== Examples
# Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments
# and newer RESTful routes. Current Rails style favors RESTful routes whenever possible, so base
...
...
@@ -274,6 +280,12 @@ def link_to(name = nil, options = nil, html_options = nil, &block)
# * <tt>:form_class</tt> - This controls the class of the form within which the submit button will
# be placed
#
# ==== Data attributes
#
# * <tt>:confirm</tt> - This will use the unobtrusive JavaScript driver to
# prompt with the question specified. If the user accepts, the link is
# processed normally, otherwise no action is taken.
#
# ==== Examples
# <%= button_to "New", :action => "new" %>
# # => "<form method="post" action="/controller/new" class="button_to">
...
...
@@ -623,8 +635,15 @@ def convert_options_to_data_attributes(options, html_options)
html_options
=
html_options
.
stringify_keys
html_options
[
'data-remote'
]
=
'true'
if
link_to_remote_options?
(
options
)
||
link_to_remote_options?
(
html_options
)
confirm
=
html_options
.
delete
(
'confirm'
)
method
=
html_options
.
delete
(
'method'
)
if
confirm
ActiveSupport
::
Deprecation
.
warn
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead"
html_options
[
"data-confirm"
]
=
confirm
end
add_method_to_attributes!
(
html_options
,
method
)
if
method
html_options
...
...
actionpack/test/template/form_tag_helper_test.rb
浏览文件 @
9345a116
...
...
@@ -386,6 +386,15 @@ def test_submit_tag_with_confirmation
)
end
def
test_submit_tag_with_deprecated_confirmation
assert_deprecated
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead"
do
assert_dom_equal
(
%(<input name='commit' type='submit' value='Save' data-confirm="Are you sure?" />)
,
submit_tag
(
"Save"
,
:confirm
=>
"Are you sure?"
)
)
end
end
def
test_button_tag
assert_dom_equal
(
%(<button name="button" type="submit">Button</button>)
,
...
...
@@ -444,6 +453,15 @@ def test_button_tag_with_confirmation
)
end
def
test_button_tag_with_deprecated_confirmation
assert_deprecated
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead"
do
assert_dom_equal
(
%(<button name="button" type="submit" data-confirm="Are you sure?">Save</button>)
,
button_tag
(
"Save"
,
:type
=>
"submit"
,
:confirm
=>
"Are you sure?"
)
)
end
end
def
test_image_submit_tag_with_confirmation
assert_dom_equal
(
%(<input type="image" src="/images/save.gif" data-confirm="Are you sure?" />)
,
...
...
@@ -451,6 +469,16 @@ def test_image_submit_tag_with_confirmation
)
end
def
test_image_submit_tag_with_deprecated_confirmation
assert_deprecated
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead"
do
assert_dom_equal
(
%(<input type="image" src="/images/save.gif" data-confirm="Are you sure?" />)
,
image_submit_tag
(
"save.gif"
,
:confirm
=>
"Are you sure?"
)
)
end
end
def
test_color_field_tag
expected
=
%{<input id="car" name="car" type="color" />}
assert_dom_equal
(
expected
,
color_field_tag
(
"car"
))
...
...
actionpack/test/template/url_helper_test.rb
浏览文件 @
9345a116
...
...
@@ -94,6 +94,15 @@ def test_button_to_with_javascript_confirm
)
end
def
test_button_to_with_deprecated_confirm
assert_deprecated
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead"
do
assert_dom_equal
(
"<form method=
\"
post
\"
action=
\"
http://www.example.com
\"
class=
\"
button_to
\"
><div><input data-confirm=
\"
Are you sure?
\"
type=
\"
submit
\"
value=
\"
Hello
\"
/></div></form>"
,
button_to
(
"Hello"
,
"http://www.example.com"
,
:confirm
=>
"Are you sure?"
)
)
end
end
def
test_button_to_with_javascript_disable_with
assert_dom_equal
(
"<form method=
\"
post
\"
action=
\"
http://www.example.com
\"
class=
\"
button_to
\"
><div><input data-disable-with=
\"
Greeting...
\"
type=
\"
submit
\"
value=
\"
Hello
\"
/></div></form>"
,
...
...
@@ -112,6 +121,15 @@ def test_button_to_with_remote_and_javascript_confirm
)
end
def
test_button_to_with_remote_and_javascript_with_deprecated_confirm
assert_deprecated
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead"
do
assert_dom_equal
(
"<form method=
\"
post
\"
action=
\"
http://www.example.com
\"
class=
\"
button_to
\"
data-remote=
\"
true
\"
><div><input data-confirm=
\"
Are you sure?
\"
type=
\"
submit
\"
value=
\"
Hello
\"
/></div></form>"
,
button_to
(
"Hello"
,
"http://www.example.com"
,
:remote
=>
true
,
:confirm
=>
"Are you sure?"
)
)
end
end
def
test_button_to_with_remote_false
assert_dom_equal
(
"<form method=
\"
post
\"
action=
\"
http://www.example.com
\"
class=
\"
button_to
\"
><div><input type=
\"
submit
\"
value=
\"
Hello
\"
/></div></form>"
,
...
...
@@ -220,6 +238,27 @@ def test_link_tag_with_javascript_confirm
)
end
def
test_link_tag_with_deprecated_confirm
assert_deprecated
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead"
do
assert_dom_equal
(
"<a href=
\"
http://www.example.com
\"
data-confirm=
\"
Are you sure?
\"
>Hello</a>"
,
link_to
(
"Hello"
,
"http://www.example.com"
,
:confirm
=>
"Are you sure?"
)
)
end
assert_deprecated
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead"
do
assert_dom_equal
(
"<a href=
\"
http://www.example.com
\"
data-confirm=
\"
You can't possibly be sure, can you?
\"
>Hello</a>"
,
link_to
(
"Hello"
,
"http://www.example.com"
,
:confirm
=>
"You can't possibly be sure, can you?"
)
)
end
assert_deprecated
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead"
do
assert_dom_equal
(
"<a href=
\"
http://www.example.com
\"
data-confirm=
\"
You can't possibly be sure,
\n
can you?
\"
>Hello</a>"
,
link_to
(
"Hello"
,
"http://www.example.com"
,
:confirm
=>
"You can't possibly be sure,
\n
can you?"
)
)
end
end
def
test_link_to_with_remote
assert_dom_equal
(
"<a href=
\"
http://www.example.com
\"
data-remote=
\"
true
\"
>Hello</a>"
,
...
...
@@ -269,6 +308,15 @@ def test_link_tag_using_post_javascript_and_confirm
)
end
def
test_link_tag_using_post_javascript_and_with_deprecated_confirm
assert_deprecated
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead"
do
assert_dom_equal
(
"<a href=
\"
http://www.example.com
\"
data-method=
\"
post
\"
rel=
\"
nofollow
\"
data-confirm=
\"
Are you serious?
\"
>Hello</a>"
,
link_to
(
"Hello"
,
"http://www.example.com"
,
:method
=>
:post
,
:confirm
=>
"Are you serious?"
)
)
end
end
def
test_link_tag_using_delete_javascript_and_href_and_confirm
assert_dom_equal
(
"<a href='
\#
' rel=
\"
nofollow
\"
data-confirm=
\"
Are you serious?
\"
data-method=
\"
delete
\"
>Destroy</a>"
,
...
...
@@ -277,6 +325,16 @@ def test_link_tag_using_delete_javascript_and_href_and_confirm
)
end
def
test_link_tag_using_delete_javascript_and_href_and_with_deprecated_confirm
assert_deprecated
":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm =>
\'
Text
\'
}' instead"
do
assert_dom_equal
(
"<a href='
\#
' rel=
\"
nofollow
\"
data-confirm=
\"
Are you serious?
\"
data-method=
\"
delete
\"
>Destroy</a>"
,
link_to
(
"Destroy"
,
"http://www.example.com"
,
:method
=>
:delete
,
:href
=>
'#'
,
:confirm
=>
"Are you serious?"
),
"When specifying url, form should be generated with it, but not this.href"
)
end
end
def
test_link_tag_with_block
assert_dom_equal
'<a href="/"><span>Example site</span></a>'
,
link_to
(
'/'
)
{
content_tag
(
:span
,
'Example site'
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录