I am creating a quiz application. Here are my models.
Answers
class Answer < ActiveRecord::Base
belongs_to :question
end
Questions
class Question < ActiveRecord::Base
has_many :answers
belongs_to :correct_answer, :class_name=>"Answer"
accepts_nested_attributes_for :answers, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true
end
I am trying to have a nested attributes form using the railscast 196 and 197 stuff. That way there can be infinite adds and removes when they are creating/editing.
I can create questions with answers that's fine. The issue is creating the correct_answer field. Since answers have not been saved yet, there is no id to put in the correct_answer_id form. Any ideas?