# How to display file contents from html file

**URL:** <https://www.ruby-forum.com/t/how-to-display-file-contents-from-html-file/179643>\
**Category:** Rails\
**Created:** [December 1, 2009, 5:03am UTC](https://www.ruby-forum.com/t/how-to-display-file-contents-from-html-file/179643 "2009-12-01T05:03:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [December 1, 2009, 5:03am UTC](https://www.ruby-forum.com/t/how-to-display-file-contents-from-html-file/179643/1 "2009-12-01T05:03:21Z")

</div>

I want to get file contents from html file  
after getting i want to display it in the view page.any sample

any helps  
Thanks

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [December 1, 2009, 5:13am UTC](https://www.ruby-forum.com/t/how-to-display-file-contents-from-html-file/179643/2 "2009-12-01T05:13:42Z")

</div>

Newb N. wrote:

> I want to get file contents from html file  
> after getting i want to display it in the view page.any sample
> 
> any helps  
> Thanks

Hi,  
As you want html parsing in rails. there are several gems available  
for it. one of them is “hpricot”.  
for more information refer this  
[Fast HTML parsing in Ruby with Hpricot](http://www.rubyinside.com/fast-html-parsing-in-ruby-with-hpricot-125.html).  
Hope, this will help you.

Thanks,  
Priyanka P.

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [December 1, 2009, 6:13am UTC](https://www.ruby-forum.com/t/how-to-display-file-contents-from-html-file/179643/3 "2009-12-01T06:13:06Z")

</div>

Priyanka P. wrote:

> Newb N. wrote:
> 
> > I want to get file contents from html file  
> > after getting i want to display it in the view page.any sample
> > 
> > any helps  
> > Thanks
> 
> Hi,  
> As you want html parsing in rails. there are several gems available  
> for it. one of them is “hpricot”.  
> for more information refer this  
> [Fast HTML parsing in Ruby with Hpricot](http://www.rubyinside.com/fast-html-parsing-in-ruby-with-hpricot-125.html).  
> Hope, this will help you.
> 
> Thanks,  
> Priyanka P.

hi…  
@doc = Hpricot.parse(“#{@file\_path}”)  
i tried like above…can i get all the contents of the file in this @doc  
instance variable  
can u pls provide me an example

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [December 1, 2009, 6:16am UTC](https://www.ruby-forum.com/t/how-to-display-file-contents-from-html-file/179643/4 "2009-12-01T06:16:02Z")

</div>

> hi…  
> @doc = Hpricot.parse("#{@file\_path}")  
> i tried like above…can i get all the contents of the file in this @doc  
> instance variable  
> can u pls provide me an example

@file\_path = d:/temp/History/regst.html

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [December 1, 2009, 6:46am UTC](https://www.ruby-forum.com/t/how-to-display-file-contents-from-html-file/179643/5 "2009-12-01T06:46:16Z")

</div>

Priyanka P. wrote:

> Newb N. wrote:
> 
> > I want to get file contents from html file  
> > after getting i want to display it in the view page.any sample
> > 
> > any helps  
> > Thanks
> 
> Hi,  
> As you want html parsing in rails. there are several gems available  
> for it. one of them is “hpricot”.  
> for more information refer this  
> [Fast HTML parsing in Ruby with Hpricot](http://www.rubyinside.com/fast-html-parsing-in-ruby-with-hpricot-125.html).  
> Hope, this will help you.

Nokogiri is supposed to be faster than Hpricot, for what that’s worth.

> Thanks,  
> Priyanka P.

Best,  
–Â  
MarnenÂ Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [December 1, 2009, 6:53am UTC](https://www.ruby-forum.com/t/how-to-display-file-contents-from-html-file/179643/6 "2009-12-01T06:53:26Z")

</div>

hi…’  
actually i read html file

@content = File.read ("#file\_path}")  
i dispaly in my view like \<%=@content%\>  
this causes style issues in my page …  
why waht is the problem…  
pls help me…,.
