acts_as_follower
acts_as_follower copied to clipboard
Using abstract, inherited model, without STI
When using a model that inherits from something other than ActiveRecord::Base
the plugin does not work properly.
For instance:
class User < Omnisocial::User
acts_as_followable
acts_as_follower
end
In that case the type columns in the Follow
model are populated with "Omnisocial::User" and in turn methods like user.followers_by_type('User')
will not return anything - passing 'Omnisocial::User' to that method is not what I would expect to do. user.user_followers
doesn't work either obviously, and again user.omnisocial_user_followers
seems to be too cumbersome and wrong. On top of that path helpers wouldn't work with type 'Omnisocial::User'.
To make everything work I made the class Omnisocial::User abstract:
Omnisocial::User.abstract_class = true
but for this to make the plugin work I had to account for the abstract class in the parent_class_name
method:
def parent_class_name(obj)
if obj.class.superclass != ActiveRecord::Base && !obj.class.superclass.abstract_class?
return obj.class.superclass.name
end
return obj.class.name
end
With that in place everything was working as expected for me (type columns are populated with 'User', user.user_followers
etc.)
In short/general, apart from my issues (all of which I could workaround somehow and were just added for better explanation) - using an abstract model that is being inherited from, no STI, seems to be not supported currently.