Rails 3.2.6 hates dbi gem ?

I have a bad problem

I have a small rails app .. was running fine with ruby 1.8x and rails
2.x
In my extreme stupidity 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 (2x) which is part of the complete application now.
( I can test/run the standalone pgm outside rails and there is no
problem .. it works)

This standalone program in using mysql and dbi gems
  I call this program as such from a model

     system("ruby standalonepgm.ruby -args ")

In rails 2.0 this worked without any issue.
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
dbi gem!

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

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

My question is .. 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 ?

I don’t know what the issue between rails and DBI might be, but the second bit is down to bundler. Bundler doesn’t allow you to require stuff outside the Gemfile because that’s how it’s sure that you always have a consistent set of gems around. Furthermore, when bundler is enabled it sets some environment variables (RUBYOPT, BUNDLE_GEMFILE etc…) which will be picked up by the ruby running inside your call to system and cause it to also use bundler and your Gemfile.

You could either try killing those enviroment variables e.g.

system("RUBYOPT=’’ ruby standalonepgm.rb ")

Or, probably less jacky, try changing the gemfile entry for dbi to

gem “dbi”, :require => false

which means that gem won’t be used unless someone requires it, which should hopefully avoid whatever conflict it has with rails while still allowing your script to run.

Fred

Fred - Thanks for the reply
I have tried the bundler fix .. the following works too

Bundler.with_clean_env do
   system ("ruby pgm.rb")
end

Of course rails hates dbi and it has to come off the gemfile .. i like
it that way