0

I have a small rails app, which was running fine with Ruby 1.8x and Rails 2.x. In a regrettable decision, I decided to move to Ruby 1.9.x and Rails 3, and it's a glorious pain.

My Ruby app uses MySQL, and I use Active Record for that. However there is an earlier pgm I had written to fill in the database before I did Rails (2.x), which is part of the complete application now. (I can test/run the standalone pgm outside Rails and there is no problem.)

This standalone program is using MySQL and dbi gems. I call this program as such from a model:

 system("ruby standalonepgm.rb -args ")

In Rails 2.0 this works without any issues. In 3.0 the program exits without any way to capture the error.

Running under console I see that the program dies because it can't find the dbi gem!

If I put the dbi gem in the Gemfile and do bundle date, then there is real trouble. Rails refuses to start - the rails server dies with all kind of issues. I can put in the screendump, but I think that's unimportant.

There seem to be 2 issues:

  1. DBI is surely incompatible with the gods of Rails
  2. Rails creates a sandbox, and all programs called must live in that sandbox (that's why just a require statement doesn't suffice .. it has to be in Gemfile).

Is it fixable or I am one of those who got bitten by the hidden black magic of rails, and my past 8+ weeks of effort is down the tubes?

Makoto
  • 104,088
  • 27
  • 192
  • 230
sms
  • 65
  • 7
  • Two follow-on questions. 1 - what errors do you get? 2 - Have you checked that dbi is compatible with the new version of Rails? (As an aside, it's never advisable to upgrade to a new language platform unless you can be certain that everything is compatible.) – Makoto Sep 16 '12 at 22:08
  • It's fixed by using Bundle.with_clean_env do system("ruby pgm.rb" end – sms Sep 17 '12 at 00:24
  • 1
    I'm glad you found your answer, but never think Rails has any magic associated with it. It is all plain old Ruby; magic is just code you haven't bothered to understand. – Chris Sep 17 '12 at 00:33

1 Answers1

1

It's fixed by using Bundle.with_clean_env do system("ruby pgm.rb" end

I had never read bundle doc ..this case is described in it ..

sms
  • 65
  • 7