Ruby/RoR: calling original method via super()?
- by fearless_fool
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?