0

I'm sure this is something annoyingly simple but I'm missing it. I'm trying to create multiple radio buttons in a table, using simple form that then, instead of storing the value "true" they store the value of the particular radio button in the database.

Here's my code:

<%= render layout: 'form' do |f| %>
<h1>Quotes</h1>
<div class="row">

<div class="col-md-8 col-md-offset-2">

<table class="table">
  <thead>
<tr>
  <th>Indemnity Limit</th>
  <th>Commercial<br/>Insurance</th>
</tr>
  </thead>
  <tbody>
<tr>
  <td>£1,000,000</td>
  <td><%= f.radio_button :quote, checked: true, value: "£57.50", input_html: { value: '£57.50' } %>£57.50</td>
</tr>
<tr>
  <td>£2,000,000</td>
  <td><%= f.radio_button :quote, label: '£74.00', value: "£74.00" %>£74.00</td>
</tr>
<tr>
  <td>£3,000,000</td>
  <td><%= f.radio_button :quote, id: '3', label: '£85.00', value: "£85.00" %>85.00</td>
</tr>

<tr>
  <td>£5,000,000</td>
  <td><%= f.radio_button :quote, label: '£101.50', value: "£101.50" %>£101.50</td>
</tr>
</tbody>
</table>
</div>
</div>
<% end %>

I'm trying to achieve this:

Multiple radio buttons

Thanks!

1 Answer 1

1

Rails - Radio Buttons for collection sets

You need to specify them as such:

<%= f.radio_button :quote, '35.00' %>

The first value is the attribute you're updating, and the second is the value that will be sent if selected.

If the value is an integer rather than a string, remove the quotes.

Sign up to request clarification or add additional context in comments.

3 Comments

Doesn't work using Simple Form, throws the error "invalid byte sequence in UTF-8"
Just came back to this and realised it was the "checked: true" causing the invalid byte sequence error. It needed to be after the value. Your solution worked thanks!
Happy to help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.