Предисловие: Этот вопрос весьма конкретный. Я пробовал этот мозг ... Думаю, мне нужен гуру для этого.Рельсы 4 - Комплексные отношения моделей
Концепция: «Ответчик» должен ответить на вопрос с множественным выбором (обычно с помощью> 1 правильного ответа). Пользователь выбирает правильные ответы (фотографии), а затем «Отправить».
Сорта, как это:
Моя проблема: Я не знаю, лучший способ собирать и хранить (а затем в конечном итоге получить ) данные о такого рода вещи. В частности:
- Какой пользователь попытался ответить на этот вопрос?
- Какие фотографии пользователь выбрал?
- Какая пользовательская фотография была правильной/неправильной?
- Был ли этот вопрос правильным? (Например, пользователь лишь частично правильно?)
Моя Таблица Структура:
users
id
===================================================
templates
id
prompt #"Which one needs baking?"
===================================================
choices #e.g., the image
id
name
image
===================================================
template_assignments #a join table between templates and choices
id
choice_id
template_id
correct #boolean - Is this image the correct response?
===================================================
responses #this is where I am LOST
id
user_id
template_id
--Not sure what to do with this table, maybe something like:
response_1
response_1_correct #boolean
etc....
overall_correct #boolean
-- Or would I need some other type of join table?
Мои отношения:
class Choice < ActiveRecord::Base
has_many :template_assignments
has_many :templates, :through => :template_assignments
end
class Template < ActiveRecord:Base
has_many :template_assignments, dependent: :destroy
has_many :choices, :through => :template_assignments
has_many :responses
accepts_nested_attributes_for :template_assignments, allow_destroy: true
end
class TemplateAssignment < ActiveRecord:Base
belongs_to :template
belongs_to :choice
end
class Response < ActiveRecord::Base
belongs_to :template
end
Любые предложения о том, как определить отношения между этими моделями очень полезно!
Спасибо!