Rescueing require

I have a rails application running on a shared server. As I can’t
install gems on it, I was going to put my own lib on the server if it
couldn’t find the gem. My code was as follows (in the controller)

begin
require “rubygems”
require “payment”
rescue
$: << “/home/username/rubylib”
require “payment”
end

The problem is that the rescue doesn’t get processed. When it hits the
require at line 3, the app dies. I know that the code from line 5 ($: <<
…) works as I’ve tested it with irb as well as put it standalone in
the controller on the shared server. If the rescue were processed,
everything would be fine.

Does anyone know how to get a recovery in this situation?
Thanks in advance
—Michael

Hi –

On Mon, 11 Dec 2006, Michael S. wrote:

 require "payment"

end

The problem is that the rescue doesn’t get processed. When it hits the
require at line 3, the app dies. I know that the code from line 5 ($: <<
…) works as I’ve tested it with irb as well as put it standalone in
the controller on the shared server. If the rescue were processed,
everything would be fine.

Does anyone know how to get a recovery in this situation?

Yes: you need:

rescue LoadError

rescue by itself only catches StandardError and its descendants.

David


Q. What’s a good holiday present for the serious Rails developer?
A. RUBY FOR RAILS by David A. Black (Ruby for Rails)
aka The Ruby book for Rails developers!
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)

On Dec 11, 10:01 am, Michael S.
[email protected] wrote:

end

The problem is that the rescue doesn’t get processed. When it hits the
require at line 3, the app dies. I know that the code from line 5 ($: <<
…) works as I’ve tested it with irb as well as put it standalone in
the controller on the shared server. If the rescue were processed,
everything would be fine.

Does anyone know how to get a recovery in this situation?
Thanks in advance
—Michael

If I remember correctly, gems and rails plugins have the same basic
structure (as far as loading goes) and you can unpack a gem into the
vendor/ directory. This would seem to be easier than what you’re
trying here…

-r

I have a rails application running on a shared server. As I
end

The problem is that the rescue doesn’t get processed.

A rescue clause without an explicit error class defaults to
StandardError. A failed require raises a LoadError, which is not a
subclass of StandardError. Change ‘rescue’ to ‘rescue LoadError’ and it
should work as expected.

Regards,

Dan

This communication is the property of Qwest and may contain confidential
or
privileged information. Unauthorized use of this communication is
strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and
destroy
all copies of the communication and any attachments.