Dyamically getting ActiveRecord using a string

Hi,

I have an ActiveRecord which has several dynamically created has_one
associations using a plugin

has_one :foo
has_one :bar

and when I do

@foo = @my_active_record_object.foo

everything works well.

I’d like to be able to call them dynamically using a string using

@foo = @my_active_record_object.send(‘foo’)

but this doesn’t appear to work… any thoughts?

Thanks,

Rich

On 11/10/06, Rich H [email protected] wrote:

everything works well.

I’d like to be able to call them dynamically using a string using

@foo = @my_active_record_object.send(‘foo’)

but this doesn’t appear to work… any thoughts?

That should work. Those two forms are the same for the object (unless
some
of your plugins changed “send” instance method of AR::Base =)) Any
method_missing tricks won’t distinguish those two forms of method
invocation. Maybe you’re doing something wrong elsewhere ?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs