1
<%= radio_button_tag(:gender, "male") %>    
<%= label_tag(:male, "Male") %>    
<%= radio_button_tag(:gender, "female") %>    
<%= label_tag(:female, "Female") %>

I've created a radio button. And I'm trying to get the checked value in my database. I'm getting results like

Parameters:

{
    "authenticity_token" => "", "contact_details" => {
        "name" => "kjhg", "address" => "fds", "state_id" => "2", "email" => "asdfghjk@lkfd.com", "number" => "0987654321"
    }, "gender" => "female", "commit" => "Create"
}

That radio button field is outside my table. How can I get that field inside my table and reflect the result in the database?

Wasi
  • 1,473
  • 3
  • 16
  • 32
  • Possible duplicate of [How to get value from checkbox in rails](https://stackoverflow.com/questions/30582221/how-to-get-value-from-checkbox-in-rails) – Anand Aug 13 '19 at 07:12
  • What you want to do? store value in database table? – Vishal Aug 13 '19 at 07:39

1 Answers1

1

You have to change the name attribute of the radio_button_tag according to params you require.

<%= radio_button_tag("contact_details[gender]", "male") %>    
<%= label_tag(:male, "Male") %>    
<%= radio_button_tag("contact_details[gender]", "female") %>    
<%= label_tag(:female, "Female") %>
Dyaniyal Wilson
  • 1,012
  • 10
  • 14