Now I have 3 models, item category and sub-category and 3 Tables in my database. I planed to set the association like this. Item Belongs_to :category Belongs_to :sub-category category Has_many :items Has_many :sub_category sub_category belongs_to :category Has_many :items And now I want to have some dynamic drop down list in the items/new page When I chose one category, and the sub-category will dynamically updated. what other move do I need? Is that right? It makes me feel confused with these associations.
on 2008-10-17 07:35
on 2008-10-17 08:56
Jette Chan wrote: > Now I have 3 models, item category and sub-category > and 3 Tables in my database. > > I planed to set the association like this. > > Item > Belongs_to :category > Belongs_to :sub-category > > category > Has_many :items > Has_many :sub_category > > sub_category > belongs_to :category > Has_many :items > > And now I want to have some dynamic drop down list in the items/new > page > When I chose one category, and the sub-category will dynamically > updated. > what other move do I need? > > Is that right? It makes me feel confused with these associations. category.rb has_many :sub_categories has_many :items ,:through=>:sub_categories sub_category.rb belongs_to :category has_many :items item.rb belongs_to :sub_category by use of this association you can define get any of 2 by select of any of 1 among three models for that use Ajax Updater
on 2008-10-17 12:02