Dynamic class_name for has_many relations

Posted by vooD on Stack Overflow See other posts from Stack Overflow or by vooD
Published on 2010-06-15T12:51:07Z Indexed on 2010/06/15 12:52 UTC
Read the original article Hit count: 145

I'm trying to make has_many relation with dynamic class_name attribute

class Category < ActiveRecord::Base
  has_many :ads, :class_name => ( lambda { return self.item_type } ) 
end

or

class Category < ActiveRecord::Base
  has_many :ads, :class_name => self.item_type
end

But i got errors:

can't convert Proc into String

or

undefined method `item_type' for #<Class:0xb62c6c88>

Thank you for any help!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby