Wyświetlanie postów z lipiec, 2010

Rails 3 bug that occures when using inherited callback without calling super . Nasty error when scopes are called on STI classes.

In case you are using the inherited callback in Rails3, don't forget to call super.

class BaseAttribute < ActiveRecord::Base

def self.inherited(klass)

klass.base_attribute_class.class_eval do
extend MyModule

Otherwise STI might not work properly. In my case for every inherited class I was looking for another one based on their names and extending them with some module which was defining scopes. Unofortunatelly I was getting errors that some methods was called on NilClass when I tried to use those scopes. Calling the super helped. Another thing is that with out using super the method subclasses also works badly.