2

ページごとに 1 つの部分的な形式で質問するクイズと表示を作成しました。作成を使用するときに、作成する前にチェックするラジオ ボタンの値が必要です。次にコントローラーで params[:answer] を使用すると、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
4

2 に答える 2

0

ラジオ ボタンの入力を開始する前に "f" が必要ですが、コントローラー コードは一見非常に効率が悪いように見えます。

 <%= f.radio_button :answer, "#{@ans.id}ans1" %> 
于 2013-10-15T12:39:39.343 に答える
0

実際link_to_remoteには次の投稿で、 ans が返すという回答データベースを作成しますnull.... 私の開発ログAnswersController#next

[POST] Parameters: {"passed_question"=>"3", "action"=>"next", "authenticity_token"=>"EjReUuUVAbRJ6s3k7Tj/pS7s2ENUUgTvyaiiRz9/IF8=", "exam_group_id"=>"1", "controller"=>"answers"}

これで、結果を取得するためにラジオボタンで指定された回答パラメーターが必要です

于 2013-10-15T16:59:28.827 に答える