ruby - Rails STI models with the same name but inheriting from another model -
ruby - Rails STI models with the same name but inheriting from another model -
my rails application uses sti have 2 different types of customers. 1 person client , other company customer.
so in people controller want instantiate customer. (so type attribute of person customer).
my client model inherits person model. model filename called customer.rb in companies controller want instantiate customer, 1 time again uses customer.rb, won't work because inherits person still.
how can utilize same model, each model needs inherit model?
#models/customer.rb class client < person end #models/customer.rb class client < company end
i tried moving customer.rb different directories, e.g. person/, company/ i'm not sure if correct. maybe should utilize modules?
that not work. cannot have 2 distinct classes same name, , class cannot inherit 2 classes.
maybe can utilize polymorphic association between client , person/company.
class person has_many :customers, :as => :customer_entity end class company has_many :customers, :as => :customer_entity end class client belongs_to :customer_entity, :polymorphic => true end
ruby-on-rails ruby
Comments
Post a Comment