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&fubar=baz
(notice it's &
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') ) %>
精彩评论