Jim Gagne
2007-Oct-26  21:18 UTC
Standalone ActiveRecord application can''t find ActiveRecord
I need a standalone script to load models every two hours from an
external source. I copied code from the original Ruby on Rails (RoR)
application that works fine. The problem is that on my system, even
the simplest request produces an error: it can''t find ActiveRecord.
Example:
Here''s the simplified script:
    #!/usr/bin/env ruby
    require "rubygems"
    gem "activerecord"             #new version of
''gem_require''
    ActiveRecord::Base.establish_connection(:adapter =>
''mysql'', :database => ''sample'',
:username => ''root'', :password =>
''pass'', :socket => ''/tmp/
mysql.sock'')
Here''s the output:
ruby -w sample.rb
sample.rb:5: uninitialized constant ActiveRecord (NameError)
I get the same result putting the same code into irb.
But when I modify the last line of the script to simply "puts
$:" (i.e., print the list of loaded modules), here''s the list:
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/bin
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/bin
/opt/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib
/opt/local/lib/ruby/site_ruby/1.8
/opt/local/lib/ruby/site_ruby/1.8/i686-darwin8.8.1
/opt/local/lib/ruby/site_ruby
/opt/local/lib/ruby/vendor_ruby/1.8
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin8.8.1
/opt/local/lib/ruby/vendor_ruby
/opt/local/lib/ruby/1.8
/opt/local/lib/ruby/1.8/i686-darwin8.8.1
So ActiveRecord is sitting there. What am I doing wrong??
---Jim Gagne---
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Oct-26  21:22 UTC
Re: Standalone ActiveRecord application can''t find ActiveRecord
On 26 Oct 2007, at 22:18, Jim Gagne wrote:> > I need a standalone script to load models every two hours from an > external source. I copied code from the original Ruby on Rails (RoR) > application that works fine. The problem is that on my system, even > the simplest request produces an error: it can''t find ActiveRecord. > Example: > > Here''s the simplified script: > #!/usr/bin/env ruby > require "rubygems" > gem "activerecord" #new version of ''gem_require'' >Try require "rubygems" require "active_record" Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---