I am trying to set a true/false value to a radio button in a form in rails 4. I found a post on stackoverflow and implemented my radio buttons accordingly but I always get false as a value.
my code
<div><%= label :access_rights, 'Read Only', :value => "false" %></div>
<%= f.radio_button :access_rights, "Read Only", :checked => true , false%></div>
<div><%= label :access_rights, 'Read and Write', :value => "true" %></div>
<%= f.radio_button :access_rights, "Read and Write", true %>
Is there a different way to set values for a radio button in rails 4?
EDIT:
in my controller
def access_params
params.require(:accessor).permit(:email, :access_rights)
end
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"t/da2RRBi4KsyndnHx4WNZLoOHu9DVlAWtl/59NPiMc=",
"accessor"=>{"accessor_id"=>"email",
"access_rights"=>"Read and Write"},
"commit"=>"Grant Permission"}
I believe the other answer's labels wouldn't work right. Here's an example with the labels corrected.
<div>
<%= label :access_rights, "Read Only", value: false %>
<%= f.radio_button :access_rights, false, :checked => true, :value => false %>
</div>
<div>
<%= label :access_rights, "Read and Write", value: true %>
<%= f.radio_button :access_rights, true, :value => true%>
</div>
Issue was resolved
<div><%= label :access_rights, "Read Only" %>
<%= f.radio_button :access_rights, false , :checked => true , :value => false %></div>
<br>
<div><%= label :access_rights, "Read and Write"%>
<%= f.radio_button :access_rights, true, :value => true%></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With