Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9685080a
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,发现更多精彩内容 >>
提交
9685080a
编写于
11月 23, 2014
作者:
X
Xavier Noria
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
let mailer templates generate URLs by default [Xavier Noria, Richard Schneeman]
上级
cdd90f39
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
107 addition
and
12 deletion
+107
-12
actionmailer/CHANGELOG.md
actionmailer/CHANGELOG.md
+7
-0
actionmailer/test/fixtures/url_test_mailer/exercise_url_for.erb
...mailer/test/fixtures/url_test_mailer/exercise_url_for.erb
+1
-0
actionmailer/test/url_test.rb
actionmailer/test/url_test.rb
+60
-0
actionpack/lib/action_dispatch/routing/route_set.rb
actionpack/lib/action_dispatch/routing/route_set.rb
+6
-2
actionpack/lib/action_dispatch/routing/url_for.rb
actionpack/lib/action_dispatch/routing/url_for.rb
+6
-0
actionview/lib/action_view/rendering.rb
actionview/lib/action_view/rendering.rb
+2
-2
actionview/lib/action_view/routing_url_for.rb
actionview/lib/action_view/routing_url_for.rb
+25
-8
未找到文件。
actionmailer/CHANGELOG.md
浏览文件 @
9685080a
*
`link_to`
and
`url_for`
generate URLs by default in templates, it is no
longer needed to pass
`only_path: false`
.
Fixes #16497 and #16589.
*Xavier Noria*, *Richard Schneeman*
*
Attachments can be added while rendering the mail template.
Fixes #16974.
...
...
actionmailer/test/fixtures/url_test_mailer/exercise_url_for.erb
0 → 100644
浏览文件 @
9685080a
<%=
url_for
(
@options
)
%>
<%=
@url
%>
actionmailer/test/url_test.rb
浏览文件 @
9685080a
...
...
@@ -23,9 +23,32 @@ def signed_up_with_url(recipient)
mail
(
to:
recipient
,
subject:
"[Signed up] Welcome
#{
recipient
}
"
,
from:
"system@loudthinking.com"
,
date:
Time
.
local
(
2004
,
12
,
12
))
end
def
exercise_url_for
(
options
)
@options
=
options
@url
=
url_for
(
@options
)
mail
(
from:
'from@example.com'
,
to:
'to@example.com'
,
subject:
'subject'
)
end
end
class
ActionMailerUrlTest
<
ActionMailer
::
TestCase
class
DummyModel
def
self
.
model_name
OpenStruct
.
new
(
route_key:
'dummy_model'
)
end
def
persisted?
false
end
def
model_name
self
.
class
.
model_name
end
def
to_model
self
end
end
def
encode
(
text
,
charset
=
"UTF-8"
)
quoted_printable
(
text
,
charset
)
...
...
@@ -40,10 +63,47 @@ def new_mail( charset="UTF-8" )
mail
end
def
assert_url_for
(
expected
,
options
,
relative:
false
)
expected
=
"http://www.basecamphq.com
#{
expected
}
"
if
expected
.
start_with?
(
'/'
)
&&
!
relative
urls
=
UrlTestMailer
.
exercise_url_for
(
options
).
body
.
to_s
.
chomp
.
split
assert_equal
expected
,
urls
.
first
assert_equal
expected
,
urls
.
second
end
def
setup
@recipient
=
'test@localhost'
end
def
test_url_for
UrlTestMailer
.
delivery_method
=
:test
AppRoutes
.
draw
do
get
':controller(/:action(/:id))'
get
'/welcome'
=>
'foo#bar'
,
as:
'welcome'
get
'/dummy_model'
=>
'foo#baz'
,
as:
'dummy_model'
end
# string
assert_url_for
'http://foo/'
,
'http://foo/'
# symbol
assert_url_for
'/welcome'
,
:welcome
# hash
assert_url_for
'/a/b/c'
,
controller:
'a'
,
action:
'b'
,
id:
'c'
assert_url_for
'/a/b/c'
,
{
controller:
'a'
,
action:
'b'
,
id:
'c'
,
only_path:
true
},
relative:
true
# model
assert_url_for
'/dummy_model'
,
DummyModel
.
new
# class
assert_url_for
'/dummy_model'
,
DummyModel
# array
assert_url_for
'/dummy_model'
,
[
DummyModel
]
end
def
test_signed_up_with_url
UrlTestMailer
.
delivery_method
=
:test
...
...
actionpack/lib/action_dispatch/routing/route_set.rb
浏览文件 @
9685080a
...
...
@@ -457,7 +457,7 @@ def #{name}
RUBY
end
def
url_helpers
(
include_path_helpers
=
true
)
def
url_helpers
(
supports_path
=
true
)
routes
=
self
Module
.
new
do
...
...
@@ -484,7 +484,7 @@ def url_options; {}; end
# named routes...
include
url_helpers
if
include_path_helpers
if
supports_path
path_helpers
=
routes
.
named_routes
.
path_helpers_module
else
path_helpers
=
routes
.
named_routes
.
path_helpers_module
(
true
)
...
...
@@ -502,6 +502,10 @@ def url_options; {}; end
# UrlFor (included in this module) add extra
# conveniences for working with @_routes.
define_method
(
:_routes
)
{
@_routes
||
routes
}
define_method
(
:_generate_paths_by_default
)
do
supports_path
end
end
end
...
...
actionpack/lib/action_dispatch/routing/url_for.rb
浏览文件 @
9685080a
...
...
@@ -184,6 +184,12 @@ def _with_routes(routes)
def
_routes_context
self
end
private
def
_generate_paths_by_default
true
end
end
end
end
actionview/lib/action_view/rendering.rb
浏览文件 @
9685080a
...
...
@@ -35,13 +35,13 @@ def process(*) #:nodoc:
module
ClassMethods
def
view_context_class
@view_context_class
||=
begin
include_path_helpers
=
supports_path?
supports_path
=
supports_path?
routes
=
respond_to?
(
:_routes
)
&&
_routes
helpers
=
respond_to?
(
:_helpers
)
&&
_helpers
Class
.
new
(
ActionView
::
Base
)
do
if
routes
include
routes
.
url_helpers
(
include_path_helpers
)
include
routes
.
url_helpers
(
supports_path
)
include
routes
.
mounted_helpers
end
...
...
actionview/lib/action_view/routing_url_for.rb
浏览文件 @
9685080a
...
...
@@ -80,21 +80,38 @@ def url_for(options = nil)
when
String
options
when
nil
super
(
{
:only_path
=>
true
}
)
super
(
only_path:
_generate_paths_by_default
)
when
Hash
options
=
options
.
symbolize_keys
options
[
:only_path
]
=
options
[
:host
].
nil?
unless
options
.
key?
(
:only_path
)
unless
options
.
key?
(
:only_path
)
if
options
[
:host
].
nil?
options
[
:only_path
]
=
_generate_paths_by_default
else
options
[
:only_path
]
=
false
end
end
super
(
options
)
when
:back
_back_url
when
Symbol
ActionDispatch
::
Routing
::
PolymorphicRoutes
::
HelperMethodBuilder
.
path
.
handle_string_call
self
,
options
when
Array
polymorphic_path
(
options
,
options
.
extract_options!
)
when
Class
ActionDispatch
::
Routing
::
PolymorphicRoutes
::
HelperMethodBuilder
.
path
.
handle_class_call
self
,
options
if
_generate_paths_by_default
polymorphic_path
(
options
,
options
.
extract_options!
)
else
polymorphic_url
(
options
,
options
.
extract_options!
)
end
else
ActionDispatch
::
Routing
::
PolymorphicRoutes
::
HelperMethodBuilder
.
path
.
handle_model_call
self
,
options
method
=
_generate_paths_by_default
?
:path
:
:url
builder
=
ActionDispatch
::
Routing
::
PolymorphicRoutes
::
HelperMethodBuilder
.
send
(
method
)
case
options
when
Symbol
builder
.
handle_string_call
(
self
,
options
)
when
Class
builder
.
handle_class_call
(
self
,
options
)
else
builder
.
handle_model_call
(
self
,
options
)
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录