Displaying HTML code in view

Hi,

In my application i have the facility for the users to upload the file
which has code …
And when i want to view the contents of the file uploaded in my view,in
case if the uploaded file is an html file then i am not able to display
the exact code…Instead the html content in that code gets executed.

if i have uploaded example.html

sample

Hello World

I want to display each line of this file in my view.But in my view when
i use
<% myfile= File.open(example.html)%>

    <% myfile.each do |line| %>
  • <%= line %>
  • <% end%>
the lines of the html file is getting executed and just HelloWorld is displayed without the entire code getting displayed.

Can anybody help me on this?

And when i want to view the contents of the file uploaded in my view,in
case if the uploaded file is an html file then i am not able to display
the exact code…Instead the html content in that code gets executed.

I hope you try to filter the html code that people are injecting in your
page. If not then you will be awarded the “the most stupid feature of
the year” prize.

<% myfile.each do |line| %>

  • <%= line %>
  • Solution :-

  • <%=h line %> >/li>

    <% end%>

  • Siddick E. wrote:

    <% myfile.each do |line| %>

  • <%= line %>
  • Solution :-

  • <%=h line %>
  • <% end%>

    Siddick E. wrote:

    <% myfile.each do |line| %>

  • <%= line %>
  • Solution :-

  • <%=h line %> >/li>

    <% end%>

  • Thank You…It worked…