开发者

Rails 3 ActionMailer: :escape => false doesn't work, nor does raw()

开发者 https://www.devze.com 2023-03-06 14:37 出处:网络
I want to append query string parameters to URLs generated from Rails 3 ActionMailer templates, but the ampersands are being entity escaped.

I want to append query string parameters to URLs generated from Rails 3 ActionMailer templates, but the ampersands are being entity escaped.

<%= user_url(@user, :host => 'example.com', :foo => 'bar', :fubar => 'baz') %>

results in a URL with an HTML-escaped ampersand (as expected), like

http://example.com/user/123?foo=bar&amp;fubar=baz

(notice it's &amp; not &)

I don't want the escaping (because it breaks the URLs). I used to be able to add :escape => false, but this doesn't affect the result now. I tried putting the query string parameters in a string like ?foo=bar&fubar=baz and using raw() like

<%= user_url(@user, :ho开发者_StackOverflow中文版st => 'example.com') + raw("foo=bar&fubar=baz") %>

but this also escaped my ampersand.

Is there a way to pass unescaped query string parameters in HTML email URLs?

Thanks in advance!

Tom


Found this in the Rails tickets. It's marked as 'closed', but still appears to be a problem as of 3.1.0.rc4.

https://github.com/rails/rails/issues/687

EDIT: I was able to fix this by wrapping my url helper in raw(). E.g.

<%= raw( user_url(@user, :host => 'example.com', :foo => 'bar', :fubar => 'baz') ) %>
0

精彩评论

暂无评论...
验证码 换一张
取 消