FWIW--you can use AR in a straight ruby program. Frx--something like this
should work I think:
require "rubygems"
require "activerecord"
require "sqlite3"
ActiveRecord::Base.establish_connection(:adapter => 'sqlite', :database =>
'~/my_db.db')
c = ::ActiveRecord::Base.connection
unless c.tables.member?("features")
c.create_table(:features) do |t|
t.column :feature, :string
t.column :category, :string
t.column :count, :integer
end
c.add_index(:features, [:category, :feature], :unique => true)
end
class Feature < ActiveRecord::Base
end
f = Feature.new(:feature => "bibbity", :category => "bobbity", :count => 1)
f.save!
puts("finished!")
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Steve Hull
Sent: Thursday, May 21, 2009 2:12 PM
To: [email protected]
Subject: [Rails] Re: How to keep persistent socket connections?
Roy Pardee wrote:
> you'll have a better time doing this entirely outside of rails.
Yeah I've definitely considered this... let's call this "Plan B". :)
This is because I would love to have access to all the CRUD/easy persistence
provided by ActiveRecord, while keeping open sockets.
Anyway I'm running into a problem when I try to add class instance variables to
a class that inherits from ActiveRecord. I've tried the method outlined here:
http://74.125.93.132/search?q=cache:8FvmwfP_gDwJ:www.continuousthinking.com/2006/11/17/ruby-class-variable-or-class-instance-variables+ruby-class-variable-or-class-instance-variables&cd=5&hl=en&ct=clnk
(linked through google's cache since the site is down). I got the following
error:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.columns
Same error when I tried to define the class instance vars using
:class_inheritable_accessor.
Perhaps it's unsupported to add class inheritable attributes to a descendent
ActiveRecord class? I also have found very little talk of
class_inheritable_accessor, so perhaps this is no longer maintained? I would
really appreciate some pointers re:class instance variables in rails...
Thanks,
Steve
--
Posted via http://www.ruby-forum.com/.
GHC Confidentiality Statement
This message and any attached files might contain confidential information
protected by federal and state law. The information is intended only for the
use of the individual(s) or entities originally named as addressees. The
improper disclosure of such information may be subject to civil or criminal
penalties. If this message reached you in error, please contact the sender and
destroy this message. Disclosing, copying, forwarding, or distributing the
information by unauthorized individuals or entities is strictly prohibited by
law.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---