Hi,
I have a script which is using ActiveRecord for database queries outside
of a rails app. It seems to work fine for doing finds on models, but
everytime I try to create a new model object and then save it, I always
get the error:
MyModel.new({:name=>‘foo’}).save gives
NoMethodError: undefined method `read_inheritable_attribute’ for
#MyModel:0x251f7d8
I’ve got a require for active_support. Is there anything else I have to
do to get this to work?
Thanks,
Ray
Hmm well after some investigating I’ve figured out what’s causing the
problem…
To give some background, I’m trying to use my models from my rails
project in an outside ruby script. So I have my models live in a sub
folder of the ruby app (via svn externals) and then I use them in my
ruby script. However, one of these models is using the rails plugin
validates_multiparameter_assignments. Unfortunately I don’t really need
this plugin in my script, but I really want to use the same model files
from the rails app so I have to live with it. Everytime I tried to use
this model in my ruby script I’d get errors saying the
validates_multiparameter_assignments method didnt exist. In order to
get it to work, I required all the plugin files and used the line:
ActiveRecord::Base.send :include,
ActiveRecord::Validations::ClassMethods
While this got rid of the errors and allowed me to do finds on the
model, this line however, seemed to have an adverse effect on the
save/create methods of ActiveRecord giving me the missing active_support
methods I had in my previous post.
When I remove the include statement, I don’t get any errors and
everything works fine. So somehow this include/plugin is affecting
things.
For the time being, I’m just copying the troublesome rail’s model into
my script without the plugin stuff and everything is working,
unfortunately its not very dry.
If anyone has any light to shed on this, it’d be a big help! Thanks.
Cheers,
Ray
Raymond O’Connor wrote:
Hi,
I have a script which is using ActiveRecord for database queries outside
of a rails app. It seems to work fine for doing finds on models, but
everytime I try to create a new model object and then save it, I always
get the error:
MyModel.new({:name=>‘foo’}).save gives
NoMethodError: undefined method `read_inheritable_attribute’ for
#MyModel:0x251f7d8
I’ve got a require for active_support. Is there anything else I have to
do to get this to work?
Thanks,
Ray
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.