Reading a file from my application (silently)

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
?

On Tue, Jul 29, 2008 at 9:56 AM, Michael Zellmann
[email protected] 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


http://www.robbyonrails.com/
aim: planetargon

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs