# How to read & render a text file?

**URL:** <https://www.ruby-forum.com/t/how-to-read-render-a-text-file/141173>\
**Category:** Rails\
**Created:** [June 23, 2008, 9:00am UTC](https://www.ruby-forum.com/t/how-to-read-render-a-text-file/141173 "2008-06-23T09:00:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![donvito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c67d28/32.png) [@donvito](https://www.ruby-forum.com/u/donvito)\
**Post date:** [June 23, 2008, 9:00am UTC](https://www.ruby-forum.com/t/how-to-read-render-a-text-file/141173/1 "2008-06-23T09:00:13Z")

</div>

Hello Everyone.

There is a method withing controller which is supposed to

1. read a text file
2. puts its content into the output

Problem: Output shows up in console window while not showing in html  
output.

Method itself:  
def print\_file\_contents  
file = “path/to/the/file”  
infile = File.open(file, ‘r’)  
while line = infile.gets  
puts line  
end

View template (print\_file\_contents.text.erb) :  
\<%= hp.print\_file\_contents %\>

Note: the console output is correct. The only problem is it doesn’t  
show in the browser.

Thanks in advance.  
DonVito.

---

<div class="post-metadata">

**Author:** ![donvito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c67d28/32.png) [@donvito](https://www.ruby-forum.com/u/donvito)\
**Post date:** [June 23, 2008, 9:04am UTC](https://www.ruby-forum.com/t/how-to-read-render-a-text-file/141173/2 "2008-06-23T09:04:54Z")

</div>

On Jun 23, 12:49 am, DonVito [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello Everyone.
> 
> There is a method withing controller which is supposed to
> 
> 1. read a text file
> 2. puts its content into the output

puts does nothing useful in a view. Your method needs to return what  
it wants displayed.

Fred
