In my rails application_helper.rb file, there is a parse method. Inside that method is a string variable html, which contains
<form>
, other html tags, and
in its value. I will call parse inside my view index.html.erb, with
<%= parse() %>
The call to parse will output the value of the html variable.
Quite unexpectedly, I noticed that the view renders a webpage which the browser didn't process at all, i.e., the webpage contains the writing
<form>
instead of rendering a form; and so on for all the other tags, such as
<br>.
And
was also not replaced by a corresponding space.
On checking the source code of the webpage, I noticed that all the ampersands(such as of
) was sent by the view to the browser as
&
and < was sent as
<
and similiarly for >.
So, what did happen? Putting
<parse()>
inside
<%= %>
processed the value of html before handing it out to the browser? Why?
Another piece of the puzzle is, the webpage was rendered fine when I put parse() inside
<%== %>
(I know
<%== %>
is not a correct syntax, I just discovered this piece of puzzle about it by mistake.)
So what is going on?