I have the following object:

# Table name: interests # # id :integer not null, primary key # client_id :integer # condition :string(255) belongs_to :client

I use the following form to create new objects:

= simple_form_for interest do |f| = f.error_notification .form-inputs = f.hidden_field :client_id, value: interest.client_id = f.input :condition, as: :radio_buttons, collection: ['Used', 'New'], boolean_style: :inline .form-actions = f.button :submit

I render this form multiple times on the same page and am having an issue with the IDs of each radio button input matching an ID of the same input in every form on the page.

This is what is rendered multiple times on the page:

<div class="input radio_buttons optional interest_condition"> <label class="radio_buttons optional control-label">Condition</label> <span class="radio"> <input class="radio_buttons optional" id="interest_condition_used" name="interest[condition]" type="radio" value="Used"> <label class="collection_radio_buttons" for="interest_condition_used">Used</label> </input> </span> <span class="radio"> <input class="radio_buttons optional" id="interest_condition_new" name="interest[condition]" type="radio" value="New"> <label class="collection_radio_buttons" for="interest_condition_new">New</label> </input> </span> </div>

My attempted solution:

Every form has access to a unique id through interest.client_id . I intend on changing the id on the input and the for on the following label to something using that id to ensure every version is unique:

= f.input :condition, as: :radio_buttons, collection: ['Used', 'New'], boolean_style: :inline, input_html: { id: 'interest_condition' + interest.client_id.to_s}, label_html: {for: 'interest_condition' + interest.client_id.to_s}

But this does two things wrong:

I lose the dynamic id that is typically generated by the collection, each id / for is literally interest_condition#{interest.client_id} rather than interest_condition_new#{interest.client_id} and interest_condition_used#{interest.client_id} .

/ is literally rather than and . And assigning the label_html for value with label_html: {for: 'interest_condition' + interest.client_id.to_s} assigns the for value for the parent label for the collection of radio buttons rather than the label that comes after the radio button itself (this is enabled with boolean_style: :inline )

Example of code generated by above code:

<div class="input radio_buttons optional interest_condition"> <label class="radio_buttons optional control-label" for="interest_condition7"> Condition </label> <span class="radio"> <input class="radio_buttons optional" id="interest_condition7" name="interest[condition]" type="radio" value="Used"> <label class="collection_radio_buttons" for="interest_condition_used"> Used </label> </span> <span class="radio"> <input class="radio_buttons optional" id="interest_condition7" name="interest[condition]" type="radio" value="New"> <label class="collection_radio_buttons" for="interest_condition_new"> New </label> </span> </div>