# Displaying HTML code in view

**URL:** <https://www.ruby-forum.com/t/displaying-html-code-in-view/164228>\
**Category:** Rails\
**Created:** [March 30, 2009, 7:20am UTC](https://www.ruby-forum.com/t/displaying-html-code-in-view/164228 "2009-03-30T07:20:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![charanya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charanya](https://www.ruby-forum.com/u/charanya)\
**Post date:** [March 30, 2009, 7:20am UTC](https://www.ruby-forum.com/t/displaying-html-code-in-view/164228/1 "2009-03-30T07:20:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![charanya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charanya](https://www.ruby-forum.com/u/charanya)\
**Post date:** [March 30, 2009, 7:33am UTC](https://www.ruby-forum.com/t/displaying-html-code-in-view/164228/2 "2009-03-30T07:33:30Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![charanya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charanya](https://www.ruby-forum.com/u/charanya)\
**Post date:** [March 30, 2009, 7:42am UTC](https://www.ruby-forum.com/t/displaying-html-code-in-view/164228/3 "2009-03-30T07:42:03Z")

</div>

> \<% myfile.each do |line| %\>
> 
> - \<%= line %\>

Solution :-

- \<%=h line %\> \>/li\>

> \<% end%\>

---

<div class="post-metadata">

**Author:** ![charanya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charanya](https://www.ruby-forum.com/u/charanya)\
**Post date:** [March 30, 2009, 7:44am UTC](https://www.ruby-forum.com/t/displaying-html-code-in-view/164228/4 "2009-03-30T07:44:06Z")

</div>

Siddick E. wrote:

> \<% myfile.each do |line| %\>
> 
> - \<%= line %\>

Solution :-

- \<%=h line %\> 

> \<% end%\>

---

<div class="post-metadata">

**Author:** ![charanya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b5e925/32.png) [@charanya](https://www.ruby-forum.com/u/charanya)\
**Post date:** [March 30, 2009, 8:45am UTC](https://www.ruby-forum.com/t/displaying-html-code-in-view/164228/5 "2009-03-30T08:45:34Z")

</div>

Siddick E. wrote:

> > \<% myfile.each do |line| %\>
> > 
> > - \<%= line %\>
> 
> Solution :-
> 
> - \<%=h line %\> \>/li\>
> 
> > \<% end%\>

Thank You…It worked…
