Rails: Overriding ActiveRecord association method

后端 未结 7 1385
忘了有多久
忘了有多久 2020-12-05 02:21

Is there a way to override one of the methods provided by an ActiveRecord association?

Say for example I have the following typical polymorphic has_many :through ass

7条回答
  •  不思量自难忘°
    2020-12-05 02:57

    I think you wanted def tags.<<(*new_tags) for the signature, which should work, or the following which is equivalent and a bit cleaner if you need to override multiple methods.

    class << tags
      def <<(*new_tags)
        # rawr!
      end
    end
    

提交回复
热议问题