title: Why do all my radio buttons share a single selection?
body: <p>I'm trying to build a survey app and I've hit a roadblock. When I'm submitting a response to a survey, all my answers share the same radio button selection id which means that I can <strong>only select one radio button across multiple questions</strong> whereas I want this to be one radio button <em>per</em> question.</p>
  
  <p>I'm baffled and would very much appreciate some help.</p>
  
  <p>I'm using simple_form for this project.</p>
  
  <h2>views/responses/_form.html.erb</h2>
  
  <pre><code>&lt;%= @response %&gt;
  &lt;%= @response.survey_id %&gt;
  
  &lt;%= @survey.name %&gt;
  
  &lt;p&gt;
    &lt;strong&gt;Name:&lt;/strong&gt;
    &lt;%= @survey.name %&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
    &lt;strong&gt;End date:&lt;/strong&gt;
    &lt;%= @survey.end_date %&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
    &lt;%= simple_form_for [@survey, @response] do |f| %&gt;
      &lt;!-- Survey id --&gt;
      &lt;%= f.hidden_field :survey_id, :value =&gt; @survey.id %&gt;
  
        &lt;!-- Questions --&gt;
        &lt;ol&gt;
          &lt;% @survey.questions.each do |q| %&gt;
            &lt;li&gt;&lt;%= q.content %&gt;&lt;/li&gt;
  
            &lt;!-- Iterate through answers for this question --&gt;
            &lt;%= f.simple_fields_for :answers do |a| %&gt;
              &lt;%= f.association :answers, collection: q.answers, as: :radio_buttons, :item_wrapper_class =&gt; 'test_class', include_blank: false %&gt;
            &lt;% end %&gt;
  
          &lt;% end %&gt;
        &lt;/ol&gt;
  
  
      &lt;%= f.submit %&gt;
    &lt;% end %&gt;
  &lt;/p&gt;
  </code></pre>
  
  <h2>Models</h2>
  
  <h2>survey.rb</h2>
  
  <pre><code>class Survey &lt; ApplicationRecord
    has_many :questions, :dependent =&gt; :destroy
    has_and_belongs_to_many :responses
  
    validates_presence_of :name
    accepts_nested_attributes_for :questions, allow_destroy: true
  end 
  </code></pre>
  
  <h2>question.rb</h2>
  
  <pre><code>class Question &lt; ApplicationRecord
    belongs_to :survey, optional: true
    has_many :answers, :dependent =&gt; :destroy
    accepts_nested_attributes_for :answers, allow_destroy: true
  end
  </code></pre>
  
  <h2>answer.rb</h2>
  
  <pre><code>class Answer &lt; ApplicationRecord
    belongs_to :question, optional: true
    belongs_to :response, optional: true
  
    def to_label
      "#{content}"
    end
  end
  </code></pre>
  
  <h2>response.rb</h2>
  
  <pre><code>class Response &lt; ApplicationRecord
    belongs_to :survey, optional: true
    belongs_to :user, optional: true
  
    has_and_belongs_to_many :answers, :dependent =&gt; :destroy
  end
  </code></pre>
  
  <p>Thanks,
  Bhams</p>
  
  <p>Edit:</p>
  
  <h2>Generated HTML</h2>
  
  <pre><code>&lt;p&gt;
    &lt;form novalidate="novalidate" class="simple_form new_response" id="new_response" action="/surveys/9/responses" accept-charset="UTF-8" method="post"&gt;&lt;input name="utf8" type="hidden" value="&amp;#x2713;" /&gt;&lt;input type="hidden" name="authenticity_token" value="39QorGeTDhu7pojy3L6gbZ1GZh9yBhqZphFMRWD++Ghd2ScWeLVEcdyhD9Ym0JyKHLptghvLOnJP9UlmHn32Bw==" /&gt;
      &lt;!-- Survey id --&gt;
      &lt;input value="9" type="hidden" name="response[survey_id]" id="response_survey_id" /&gt;
  
        &lt;!-- Questions --&gt;
        &lt;ol&gt;
            &lt;li&gt;222&lt;/li&gt;
  
            &lt;!-- Iterate through answers for this question --&gt;
  
              &lt;div class="input radio_buttons optional response_answers"&gt;&lt;label class="radio_buttons optional"&gt;Answers&lt;/label&gt;&lt;input type="hidden" name="response[answer_ids]" value="" /&gt;&lt;span class="radio test_class"&gt;&lt;label for="response_answer_ids_35"&gt;&lt;input class="radio_buttons optional" type="radio" value="35" name="response[answer_ids]" id="response_answer_ids_35" /&gt;11111&lt;/label&gt;&lt;/span&gt;&lt;span class="radio test_class"&gt;&lt;label for="response_answer_ids_36"&gt;&lt;input class="radio_buttons optional" type="radio" value="36" name="response[answer_ids]" id="response_answer_ids_36" /&gt;2222&lt;/label&gt;&lt;/span&gt;&lt;span class="radio test_class"&gt;&lt;label for="response_answer_ids_37"&gt;&lt;input class="radio_buttons optional" type="radio" value="37" name="response[answer_ids]" id="response_answer_ids_37" /&gt;33333&lt;/label&gt;&lt;/span&gt;&lt;span class="radio test_class"&gt;&lt;label for="response_answer_ids_38"&gt;&lt;input class="radio_buttons optional" type="radio" value="38" name="response[answer_ids]" id="response_answer_ids_38" /&gt;444444&lt;/label&gt;&lt;/span&gt;&lt;span class="radio test_class"&gt;&lt;label for="response_answer_ids_39"&gt;&lt;input class="radio_buttons optional" type="radio" value="39" name="response[answer_ids]" id="response_answer_ids_39" /&gt;55555&lt;/label&gt;&lt;/span&gt;&lt;/div&gt;
  
            &lt;li&gt;33333333333&lt;/li&gt;
  
            &lt;!-- Iterate through answers for this question --&gt;
  
              &lt;div class="input radio_buttons optional response_answers"&gt;&lt;label class="radio_buttons optional"&gt;Answers&lt;/label&gt;&lt;input type="hidden" name="response[answer_ids]" value="" /&gt;&lt;span class="radio test_class"&gt;&lt;label for="response_answer_ids_40"&gt;&lt;input class="radio_buttons optional" type="radio" value="40" name="response[answer_ids]" id="response_answer_ids_40" /&gt;4444444444444&lt;/label&gt;&lt;/span&gt;&lt;span class="radio test_class"&gt;&lt;label for="response_answer_ids_41"&gt;&lt;input class="radio_buttons optional" type="radio" value="41" name="response[answer_ids]" id="response_answer_ids_41" /&gt;55555&lt;/label&gt;&lt;/span&gt;&lt;/div&gt;
  
        &lt;/ol&gt;
  
  
      &lt;input type="submit" name="commit" value="Create Response" data-disable-with="Create Response" /&gt;
  &lt;/form&gt;&lt;/p&gt;
  </code></pre>