Ruby/RoR: calling original method via super()?

Posted by fearless_fool on Stack Overflow See other posts from Stack Overflow or by fearless_fool
Published on 2011-02-28T20:06:05Z Indexed on 2011/03/01 23:25 UTC
Read the original article Hit count: 218

Filed under:
|

In a RoR app, I want to specialize ActiveRecord's update_attributes() method in one of my models, extracting some of the attributes for special handling and passing the rest of them to the original update_attributes() method. The details:

class Premise < ActiveRecord::Base
  ...
  def update_attributes(attrs)
    attrs.each_pair do |key, val|
      unless has_attribute?(key)
        do_special_processing(key, val)
        attrs.delete(key)
      end
    end
    # use original update_attributes() to process non-special pairs
    super.update_attributes(attrs)
  end
  ...
end

The call to super.update_attributes(attr) raises an error:

undefined method `update_attributes' for true:TrueClass

... which makes me suspect I really don't understand the super keyword in Ruby. What am I missing? Specifically, how do I call the original update_attributes() method?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby