# Reading a file from my application (silently)

**URL:** <https://www.ruby-forum.com/t/reading-a-file-from-my-application-silently/144445>\
**Category:** Rails\
**Created:** [July 29, 2008, 6:56pm UTC](https://www.ruby-forum.com/t/reading-a-file-from-my-application-silently/144445 "2008-07-29T18:56:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![traceyz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@traceyz](https://www.ruby-forum.com/u/traceyz)\
**Post date:** [July 29, 2008, 6:56pm UTC](https://www.ruby-forum.com/t/reading-a-file-from-my-application-silently/144445/1 "2008-07-29T18:56:21Z")

</div>

I have an rails application that needs to read a file from its own  
directories. Say I put in in the config folder, and call it  
sometext.txt. In a controller I have

f = File.new(File.join(RAILS\_ROOT, ‘config’, ‘sometext.txt’))

then text = f.read gets me the information.

This works fine in my development environment, with the side effect that  
the file contents also get printed to my console. However, this seems to  
cause a big problem when I deploy the application. The production server  
does not want to have any print activity, so, I get an error statemtn  
that Rails application did not start successfully - same as if I had  
left a puts statement somewhere in the code.

There must be a straight-forward way to read the file without any output  
?

---

<div class="post-metadata">

**Author:** ![traceyz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@traceyz](https://www.ruby-forum.com/u/traceyz)\
**Post date:** [July 29, 2008, 8:23pm UTC](https://www.ruby-forum.com/t/reading-a-file-from-my-application-silently/144445/2 "2008-07-29T20:23:39Z")

</div>

On Tue, Jul 29, 2008 at 9:56 AM, Michael Zellmann  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the file contents also get printed to my console. However, this seems to  
> cause a big problem when I deploy the application. The production server  
> does not want to have any print activity, so, I get an error statemtn  
> that Rails application did not start successfully - same as if I had  
> left a puts statement somewhere in the code.
> 
> There must be a straight-forward way to read the file without any output  
> ?

What are your goals with this approach? Is this a configuration thing?

If so, you might look into using YAML for config files and then you  
can load up your yml file and define variables to access in your  
application.

Robby

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://www.robbyonrails.com/](http://www.robbyonrails.com/)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]

---

<div class="post-metadata">

**Author:** ![traceyz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@traceyz](https://www.ruby-forum.com/u/traceyz)\
**Post date:** [July 29, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/reading-a-file-from-my-application-silently/144445/3 "2008-07-29T23:25:56Z")

</div>

Robby R. wrote:

> What are your goals with this approach? Is this a configuration thing?
> 
> If so, you might look into using YAML for config files and then you  
> can load up your yml file and define variables to access in your  
> application.
> 
> Robby
> 
> –  
> Robby R.  
> Chief Evangelist, Partner
> 
> PLANET ARGON, LLC  
> design // development // hosting
> 
> [http://www.planetargon.com/](http://www.planetargon.com/)  
> [http://www.robbyonrails.com/](http://www.robbyonrails.com/)  
> aim: planetargon
> 
> +1 503 445 2457  
> +1 877 55 ARGON [toll free]  
> +1 815 642 4068 [fax]

Thanks for your response. The file contains an RSA private key PEM file.  
I need to read it to digitally sign an authorization token. There may be  
better ways to do this than reading the file in a controller method, but  
I wanted to start simply. If it was Jaav, I would read the file in the  
servlet init method.Not sure what the RoR equivalent should be. I might  
put something in the environment.rb file ? Basically, something like  
define the file and then define a constant KEY = file.read ?
