Trying to Create a Radio Button

Hi Alex, I'm trying to create a radio button. So far, I added a field to my accounts tables using " rails g migration AddReturnToAccounts return:boolean" then modifying the migration file so that the default value is false "default : false. Then I added: <%= f.label :return %><br> <%= f.radio_button :return, class: "form-control" %> Returning Client? to _form.html.erb and it show up fine. Lastly, I added :return to def account_params in the accounts controller but it doesn't seem like it is saving the value of the button once I select it. What am I missing? I hope that I'm posting this in the correct section. Thanks Marquese

Posted over 4 years ago by Marquese Davis
Posted over 4 years ago by Alex Yang

Everything you've mentioned looks right so far. You should check to see if the value of your 'return' field is being passed correctly. You can do this by submitting the form and looking in your Rails server. Do you see the 'return' field in the list of parameters? If not, you know it's an issue with your form. On the other hand, if you do see it listed, that means that the field is being passed correctly, but that your controller is not saving the value into your database. Hope that helps!

1
Posted over 4 years ago by Marquese Davis

After a little more research, I corrected the problem by added :true after return. I also changed the "return" value after discovering that Ruby uses that value as well. Long story short, this was the lined of code I decided to use "<%= f.check_box :return_client %> Returning Client?" A check box worked better than a radio button for this situation.

1
Posted over 4 years ago by Alex Yang

Glad it's working now!

1