I have problem with STI and relationship in ActiveRecord. I think I missed something in the class methods, but I don't know for sure. Below is my models:
class User < ActiveRecord::Base
has_many :advertisements
end
class Advertisement < ActiveRecord::Base
belongs_to :user
end
class FreeAdvertisement < Advertisement
end
class PaidAdvertisement < Advertisement
end
Now I want to find all FreeAdvertisement under certain user, e.g:
u = User.find_by_username('myself')
@freebies = u.free_advertisements.all
It gives error:
undefined method `free_advertisements' for #<User:0x2360f18>
I can hack it by using u.advertisements.find :all, :conditions
, but that's not that I want to do.
Please help me to solve this problem. Thanks in advance.