Using radio buttons

Hi,

I am new to rails and so have a very basic question. I have defined a
set of radio buttons in _form.html like this:

<%= radio_button_tag(:colour, “Blue”) %>
<%= label_tag(:colour_B, “Blue”) %>

Now I want to read the value of the radio button. Eg: if the user chose
“Blue”, then I want to display the user’s name in a table under the
column Blue. I already defined the table in index.html and I have a
model called usertable that I previously defined on the command line
using:

rails generate scaffold usertable name:string colour:text

I don’t know how to actually read in the value of radio button. Do I
need to
define it somehow in the def show block in the controller? …

Thanks so much. Any help is appreciated!

cathy

you can always try this when you have that kind of problem:

In your controller:

def whatever
flash[:notice] = params
redirect_to back
end

this will print the params hash if you have a flash message div set up.
The
original way of doing this is by looking at the console, and looking at
the
hash that gets send.

Parameters: {“utf8”=>“✓”, “authenticity_token”=>“lol_omg”,
“order_details”=>{“send_to”=>“my_house”, “product_id”=>“2”}}

usually in the controller you access this hash like this:

params[:order_detail]

where

params[:order_detail] is “order_details”=>{“send_to”=>“my_house”,
“product_id”=>“2”} and params[:order_details] will return

{“send_to”=>“my_house”, “product_id”=>“2”}

so putting params into the flash will send back all the params and that
will
let you see what parameters and send and how to access them.

cathy n. wrote in post #1027986:

I am new to rails and so have a very basic question. I have defined a
set of radio buttons in _form.html like this:

<%= radio_button_tag(:colour, “Blue”) %>
<%= label_tag(:colour_B, “Blue”) %>

Now I want to read the value of the radio button. Eg: if the user chose
“Blue”, then I want to display the user’s name in a table under the
column Blue. I already defined the table in index.html and I have a
model called usertable that I previously defined on the command line
using:

Keep in mind that radio button need to be defined in a radio button
group. Create the group by using the same value for the name attribute
of each radio button in the group:

Example:

radio_button_tag ‘gender’, ‘male’

=>

radio_button_tag ‘gender’, ‘female’

=> <input id=“gender_female” name=“gender” type=“radio” value=“female”

/>

Notice the name of the two radio button are both “gender”.

The result will appear on the params like:

{“utf8”=>“✓”,
“authenticity_token”=>“joHm5S13RnrNzaLv7t7HKU48SD6h6e5MRbwYwNU6nJA=”,
“gender”=>“female”, “submit”=>“Create”}

params[:gender]

female