In this case, a specific method should be called at the class level, for example:
class Foo
include ActsAsVotable
acts_as_votable
end
Ruby has this wonderful / terrible (depending on who you ask) that you can dynamically define for the class. Here, the method acts_as_votablefirst calls has_many(which adds several mthods to the class Foo), and then adds the method cast_voteto the class Foothrough include InstanceMethods.
So you get the equivalent:
class Foo
has_many :votes, :as => :votable, :dependent => :delete_all
def cast_vote( vote )
Vote.create( :votable => self, :up => vote == :up )
end
end
source
share