Note that there are some explanatory texts on larger screens.

plurals
  1. POTo Get the radio button value in ruby on rails
    primarykey
    data
    text
    <p>I created a quiz and display that questions one per page as partial form and when i use the create i want the value of radio button that i check before create. when i use params[:answer]in my controller next, it returns null.. can anyone help me out to get the value of radio button that i checked</p> <p>Thanks in advance</p> <pre><code>&lt;div class = "y"&gt; &lt;% form_for @answer do |f|%&gt; &lt;div class = "label_field_pair"&gt; &lt;label for "questions"&gt; &lt;%= @ans.ques %&gt; &lt;/label&gt; &lt;/div&gt; &lt;br&gt; &lt;div class = "label_field_pair2"&gt; &lt;label for "options"&gt; &lt;div id = "option-1"&gt; &lt;%= radio_button_tag "answer", "#{@ans.id}ans1"%&gt;&lt;%= @ans.ans1 %&gt; &lt;/div&gt;&lt;br&gt; &lt;div id = "option-2"&gt; &lt;%= radio_button_tag "answer", "#{@ans.id}ans2"%&gt;&lt;%= @ans.ans2 %&gt; &lt;/div&gt;&lt;br&gt; &lt;div id = "option-3"&gt; &lt;%= radio_button_tag "answer", "#{@ans.id}ans3"%&gt;&lt;%= @ans.ans3 %&gt; &lt;/div&gt;&lt;br&gt; &lt;div id = "option-4"&gt; &lt;%= radio_button_tag "answer", "#{@ans.id}ans4"%&gt;&lt;%= @ans.ans4 %&gt; &lt;/div&gt;&lt;br&gt; &lt;/label&gt; &lt;/div&gt; &lt;div class="next"&gt; &lt;%= link_to_remote "Next", :before =&gt; "Element.show('loader')", :success =&gt; "Element.hide('loader')", :url=&gt;{:controller=&gt;"answers", :action=&gt;"next"}, :with =&gt; "'&amp;passed_question=#{@ans.id}&amp;'+'&amp;exam_group_id=#{@exam_group.id}&amp;'" %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/div&gt; </code></pre> <p>and in controller</p> <pre><code>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 =&gt; ['id not in (?) &amp;&amp; exam_group_id=?',answered, @exam_group]) render(:update) do |page| page.replace_html 'main', :partial =&gt; 'ans', :object =&gt; @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 =&gt; 'ans', :object =&gt; @ans end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload