I've got a nested form, structured: Question has_many Answers. So, the questions are multiple choice.
Current form view:
- semantic_form_for @question do |f|
= f.error_messages
- f.inputs do
= f.input :question
= f.semantic_fields_for :answers do |builder|
= builder.input :content, :label => "Answer", :input_html => { :class => {'required', ' ckeditor'}}
= f.buttons
My question controller looks like:
def new
@question = Question.new
4.times { @question.answers.build }
end
def create
@question = Question.new(params[:question])
@question.user_id = current_user.id
if @question.save
flash[:notice] = "Question added."
redirect_to questions_url
else
render :action => 'new'
end
end
All pretty simple. However, now I would like to 'select' the correct answer, preferably on the same page, while adding. I think I will add a new column to Questions containing 'CorrectAnswerId' of some sort. But, how can I add it in the view & controller?