我創建了一個測驗和顯示,每頁作爲部分形式提問一次,當我使用創建時,我想要創建之前檢查的單選按鈕的值。當我使用PARAMS [:答案]在我的控制器旁邊,則返回null ..誰能幫助我出去找,我提前要獲得軌道上的紅寶石單選按鈕值
<div class = "y">
<% form_for @answer do |f|%>
<div class = "label_field_pair">
<label for "questions">
<%= @ans.ques %>
</label>
</div> <br>
<div class = "label_field_pair2">
<label for "options">
<div id = "option-1">
<%= radio_button_tag "answer", "#{@ans.id}ans1"%><%= @ans.ans1 %>
</div><br>
<div id = "option-2">
<%= radio_button_tag "answer", "#{@ans.id}ans2"%><%= @ans.ans2 %>
</div><br>
<div id = "option-3">
<%= radio_button_tag "answer", "#{@ans.id}ans3"%><%= @ans.ans3 %>
</div><br>
<div id = "option-4">
<%= radio_button_tag "answer", "#{@ans.id}ans4"%><%= @ans.ans4 %>
</div><br>
</label>
</div>
<div class="next">
<%= link_to_remote "Next",
:before => "Element.show('loader')",
:success => "Element.hide('loader')",
:url=>{:controller=>"answers", :action=>"next"},
:with => "'&passed_question=#{@ans.id}&'+'&exam_group_id=#{@exam_group.id}&'"
%>
<% end %>
</div>
<% end %>
</div>
和控制器檢查
感謝單選按鈕的值
def next
@user = current_user
@student = Student.find_by_admission_no(@user.username)
@exam_group = ExamGroup.find_by_id(params[:exam_group_id])
@answer = Answer.new(params[:ans])
@answer.answer = params[:answer]
@answer.exam_group_id = @exam_group.id
@answer.user_id = @user.id
passed_question = params[:passed_question]
@answer.questions_id = passed_question
if @answer.save
@ans = Question.find_by_id(left_random, :conditions => ['id not in (?) && exam_group_id=?',answered, @exam_group])
render(:update) do |page|
page.replace_html 'main', :partial => 'ans', :object => @ans
end
end
end
def ans
@user = current_user
@student = Student.find_by_admission_no(@user.username)
@exam_group = ExamGroup.find(params[:exam_group_id])
@tot_ans = answered.count
@last_ques = (Question.count-1)
render(:update) do |page|
page.replace_html @ans, :partial => 'ans', :object => @ans
end
end
你的form_for指定'@ answer'參數,但單選按鈕的'@ ans'一部分。 – Daiku
看到你的參數將是一個很大的幫助:) –
http://stackoverflow.com/questions/7140176/saving-radio-buttons-values-in-rails –