Passing model data to a plugin called within that model

I am making a plugin which extends ActiveRecord::Base

I have the plugin working in my models in other aspects. I would like
to pass in some data to the plugin, but I can’t get the data I would
like.

so if I have:

class Stuff < ActiveRecord::Base
belongs_to :thing

my_plugin :id => self.thing.other_id

end

it chokes on figuring out what to do with self.thing.other_id.

I checked, and self isn’t recognized at the point that I am calling
my_plugin

so if i do :

class Stuff < ActiveRecord::Base
belongs_to :thing

my_plugin :id => self.class.to_s

end

when I print out :id the class result comes back as blank.

Is there a way to do this?
The closest I can get is I can sort of do self.send(:thing).send
(:other_id)
It didn’t 100% work, but it was starting to get clunky, and I didn’t
pursue the error I was creating.
There has to be something obvious I am missing.

thanks,
Charles

class Stuff < ActiveRecord::Base
belongs_to :thing

my_plugin :id => self.thing.other_id

end

This is impossible. self in the above snippet is the Stuff class. I’m
assuming you want that to use a instance of Stuff at the time some
magical method is called. You have to use a block

class Stuff < ActiveRecord::Base
my_plugin do |stuff|
{:id => stuff.thing.other_id}
end
end

The my_plugin method has to know how to store that block so that the
instance can call it, passing itself as the first argument.

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