Forum: Ruby on Rails Just ActiveRecord

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Andre P. (Guest)
on 2005-12-13 17:10
Dear all,

Is it possible to have ActiveRecord functionality
using just a Ruby script rather than generating a
full RoR application?

I'm looking for sth without interface nor control;
a single ruby script to connect, read table1,
write table2 and disconnect.

I've started declaring a

class Test < ActiveRecord::Base

end


Any thoughts ?

Many thanks,
Andre
Marcel Molina Jr. (Guest)
on 2005-12-13 17:14
(Received via mailing list)
On Tue, Dec 13, 2005 at 04:10:11PM +0100, Andre Parmeggiani wrote:
> class Test < ActiveRecord::Base
>
> end
>
> Any thoughts ?

Sure.

  require 'rubygems'     # Or require the library directly without
RubyGems
  require 'activerecord'

  ActiveRecord::Base.establish_connection(
    :adapter  => '...', # Indicate your desired adapter
    :database => '...'
  )

  class Foo < ActiveRecord::Base
  end

That's it.

marcel
Mel R. (Guest)
on 2005-12-13 17:17
(Received via mailing list)
Andre,

Have a look here:
http://blog.dangdev.com/articles/2005/11/22/using-...

This guy, I think, did what you are asking about.

HTH

Mel
HaPK (Guest)
on 2005-12-13 17:17
(Received via mailing list)
require 'rubygems'
require_gem 'activerecord'

ActiveRecord::Base.establish_connection(
  :adapter => 'mysql',
  :host => 'localhost',
  :database => 'my_database',
  :username => 'myuser',
  :password => 'mypassword'
)

class MyModel < ActiveRecord::Base
end

Then do any ussual AR activity.
Andre P. (Guest)
on 2005-12-13 18:01
Yep, absolutely sweet ! I've just add

   :socket   => "/var/run/mysql/mysql.sock"

to the parameters and bingo!

Also, from Mel's link, i've got this one:
http://www.intertwingly.net/blog/2005/08/09/Rails-...

Many thanks again
André
This topic is locked and can not be replied to.