Have radio button's label make selection too? Have radio button's label make selection too? ruby ruby

Have radio button's label make selection too?


You may found a solution but it can help others. I'm using Rails 4+.

You can make the label clickable properly using Rails' FormHelper's label method using the "value" key into params.

label(:post, :privacy, "Public Post", value: "public")# => <label for="post_privacy_public">Public Post</label>

For your code, it should be something like

<%= f.radio_button :bet_type, "moneyline" %><%= f.label :bet_type, "Moneyline", value: "moneyline" %><%= f.radio_button :bet_type, "spread" %><%= f.label :bet_type, "Spread", value: "spread" %>

Hope it helps :)


An easy way to do this for radio buttons is to place the input tag inside the label, like so:

<label>  <input />  This is an input!</label>

This is a valid way of accomplishing your goal.

In Rails the label helper can accept a block, so you could do:

<%= f.label :moneyline do %>  <%= f.radio_button :bet_type, "moneyline" %>  "Moneyline"<% end %>


<%= f.radio_button :bet_type, "moneyline" %><%= f.label :moneyline, "Moneyline", :for => "bet_type_moneyline" %>