Reputation: 4183
I have a Rails form helper and want to add a css-class to a radio button input field.
<span class="input-nile">
<%= f.radio_button :nile_administration, class: 'input__field input__field-nile radio' %>
<label class="radio-label">Nile Administration</label>
</span>
The output is
<span class="input-nile">
<input type="radio" value="{:class=>"input__field input__field-nile radio"}" name="user[nile_administration]" id="user_nile_administration_classinput__field_input__field-nile_radio">
<label class="radio-label">Nile Administration</label>
</span>
I want to achieve that the input tag of type radio get the css class "radio" like the following:
<span class="input-nile">
<input type="radio" value="" name="user[nile_administration]" class="input__field input__field-nile radio" id="user_nile_administration_classinput__field_input__field-nile_radio">
<label class="radio-label">Nile Administration</label>
</span>
How can i do that?
Upvotes: 1
Views: 3588
Reputation: 1180
You can set the custom id, classes, and other attributes for the f.radio_button as follows. Because it only takes 3 arguments. That is why using brackets.
<%= f.radio_button :entity_type, 'practice', { checked: true, id: 'entity_type_practice', class: "custom-control-input entity-radio-button" } %>
Upvotes: 0
Reputation: 456
The issue is with the place of the colon
replace
<%= f.radio_button :nile_administration, class: 'input__field input__field-nile radio' %>
with
<%= f.radio_button :nile_administration , :class => 'input__field input__field-nile radio' %>
Upvotes: 1
Reputation: 1440
I think this is work for you:
<span class="input-nile">
<%= f.radio_button :nile_administration,"",class: 'input__field input__field-nile radio', id: 'user_nile_administration_classinput__field_input__field-nile_radio'%>
<label class="radio-label">Nile Administration</label>
</span>
Upvotes: 0
Reputation: 438
Try this:
<%= f.radio_button :nile_administration, '', '', class: 'input__field input__field-nile radio' %>
As mentioned in the docs, radio_button
takes its options as the 4th argument:
radio_button(object_name, method, tag_value, options = {})
Upvotes: 1