I am developing a portal via RubyOnRails where pupils, teachers and parents can participate in different contests with their art works.
There are 3 entities: Contests, Categories (competitor categories / age groups) and Nominations (kinds of activity). Contest can have many Categories. Each ContestCategory can have many Nominations. Each Category can belong to several Contests. Every Nomination can belong to many ContestCategories. So I presume there is many-to-many relationship between Contests and Categories and many-to-many relationship between ContestCategories and Nominations. I've created following models: Contest (contest.rb), Category (category.rb), Nomination (nomination.rb), ContestCategory (contest_category.rb) and ContestCategoryNomination (contest_category_nomination.rb).
My models:
class Category < ActiveRecord::Base
has_many :contest_categories
has_many :contests, through: :contest_categories
end
class Contest < ActiveRecord::Base
has_many :contest_categories
has_many :categories, through: :contest_categories
has_many :nominations, through: :contest_categories
has_one :provision
end
class ContestCategory < ActiveRecord::Base
belongs_to :contest
belongs_to :category
has_many :contest_category_nominations
has_many :nominations, through: :contest_category_nominations
end
class ContestCategoryNomination < ActiveRecord::Base
belongs_to :contest_category
belongs_to :nomination
end
class Nomination < ActiveRecord::Base
has_many :contest_category_nominations
has_many :contest_categories, through: :contest_category_nominations
has_many :contests, through: :contest_categories
end
I want to create an ajax-based modal window during creation of new Contest to link it with Category and select multiple Nominations that belong to this Category.
- What controllers should I create to satisfy has_many relationships between my models?
- What are the naming conventions (singular and plural) in rails to satisfy my relationships? For example,
ContestsCategoriesControllerorContestCategoryNominationsControlleror may beContestCategoryNominationsController? - What action method should I create in this controllers to invoke to render this modal window? Should it be
new_categoryaction inCategoriesControllerornewaction inContestsCategoriesControllerornewaction inContestsCategoriesNominationsController?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire