0
我有一個嵌套的窗體,結構化:Question has_many Answers。所以,這些問題是多種選擇。嵌套形式has_many模型。如何從嵌套項目獲取ID?
當前表單視圖:
- 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
我的問題控制器看起來像:
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
所有非常簡單。但是,現在我想「選擇」正確的答案,最好在同一頁上添加。我想我會爲包含某種「CorrectAnswerId」的問題添加一個新列。但是,我怎樣才能在視圖&控制器中添加它?
thx lukas!完美無缺地工作。我做了一個簡單的jquery檢查,以確保一次只檢查一個複選框,也可以工作! :) – 2010-10-08 16:40:57