Reputation: 22064
hey guys when I store this string:
http://61.147.96.19/f4v/41/53283141.h264_2.f4v?10000&key=d7d7488b5dd4a35aac3e784cf4acb1a174ddc7&playtype=1&tk=2038443745&brt=3&id=tudou&itemid=30165756&fi=53283141&sz=19354294
in a variable @longurl
and use it in a erb file
<%= @longurl %>
It doesn't work, when I check the source file in the browser :
http://61.147.96.19/f4v/41/53283141.h264_2.f4v?10000&key=d7d7488b5dd4a35aac3e784cf4acb1a174ddc7&amp;playtype=1&amp;tk=2038443745&amp;brt=3&amp;id=tudou&amp;itemid=30165756&amp;fi=53283141&amp;sz=19354294
and compare the differece, it add a amp;
after each &, and I don't know how to avoid this.
BTW it seems @url
is taken by the rails by default use, I can't save anything in the variable, Could anyone tell me why?
Thanks
Upvotes: 0
Views: 636
Reputation: 4809
Before Rails 3, you used to have to code like this to make sure everything is HTML encoded:
<%= h @longurl %>
The h
method would HTML encode your string. Now, everything is HTML encoded by default. If you don't want Rails to do this for you, we now have the raw
method like this:
<%= raw @longurl %>
Read more about the raw
method here:
http://api.rubyonrails.org/classes/ActionView/Helpers/RawOutputHelper.html#method-i-raw
or read about this change in the Rails 3 release notes http://edgeguides.rubyonrails.org/3_0_release_notes.html#other-changes
Upvotes: 1
Reputation: 1257
You actually want & Read why here: http://htmlhelp.com/tools/validator/problems.html
Is it 'breaking' the method in any other way, or just because it looks different?
If @url is used by Rails, use a different variable. It shouldn't be a deal breaker.
Upvotes: 1
Reputation: 163248
You can use CGI::unescape
to decode a URL-encoded string.
<%= CGI::unescape(@longurl) %>
For HTML entities, use CGI::unescapeHTML
:
<%= CGI::unescapeHTML(@longurl) %>
Upvotes: 1