Hi there, I created few models with STI, parent model is Account, child models are CreditCard, DebitCard, etc.. several sub-models, using STI. Every model works fine individually, but I have another model user associated with account user has_many accounts account belongs_to user The problems are : 1. Cant use association to create sub-models, like User.first.creditcards.new, but I can use User.first.accounts.new. 2. How can use same controller AccountsController to create different sub-models, actually I hardly use Account Model. codes are as following http://pastie.org/439744 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The user does not know what creditcards are in your user model. You have to have an association in the user model if you want to do User.first.creditcards.new has_many :creditcards or get the users account and then check the creditcard.. Since a user has_many accounts you would have to get an account before you could create a creditcard. So something like User.first.accounts.first.creditcard.new would explain better... Or you could use has_many through and use the accounts model as the through... has_many :accounts has_many :creditcards, :through => :accounts --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Freddy, So rails doesn''t support association inheritance, I know what you mean, but I don''t like to put the sub-model association into user model, because i have about 10 sub-models like credit_card in Account, I found a plugin called "has_many_polymorphs", this plugin allow you access all the association between two parent model. One other question, if I want to use one controller to create all the sub models, how could i write all the controller actions? Thanks again, Allen On Apr 8, 1:50 am, Freddy Andersen <fre...-RCI/mp9mI1I6GGFevw1D/A@public.gmane.org> wrote:> The user does not know what creditcards are in your user model. You > have to have an association in the user model if you want to do > User.first.creditcards.new > > has_many :creditcards > > or get the users account and then check the creditcard.. Since a user > has_many accounts you would have to get an account before you could > create a creditcard. > > So something like User.first.accounts.first.creditcard.new would > explain better... > > Or you could use has_many through and use the accounts model as the > through... > > has_many :accounts > has_many :creditcards, :through => :accounts--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---