# Radio button does not get checked

**URL:** <https://www.ruby-forum.com/t/radio-button-does-not-get-checked/131052>\
**Category:** Rails\
**Created:** [March 5, 2008, 5:11pm UTC](https://www.ruby-forum.com/t/radio-button-does-not-get-checked/131052 "2008-03-05T17:11:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dbc845/32.png) [@Eva](https://www.ruby-forum.com/u/Eva)\
**Post date:** [March 5, 2008, 5:11pm UTC](https://www.ruby-forum.com/t/radio-button-does-not-get-checked/131052/1 "2008-03-05T17:11:43Z")

</div>

I am reading information out of the db, but even though the color\_ids  
match the radio\_button does not get checked. Are only strings valid  
for comparing? Id is an integer.

\<% Color.find(:all).each do |color| %\>  
\<%= radio\_button(“page”, “color\_id”, “color.id”) %\> \<%= color.name  
%\>  
  
  
\<% end %\>

Please help!  
Thank you!

---

<div class="post-metadata">

**Author:** ![Eva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dbc845/32.png) [@Eva](https://www.ruby-forum.com/u/Eva)\
**Post date:** [March 5, 2008, 5:24pm UTC](https://www.ruby-forum.com/t/radio-button-does-not-get-checked/131052/2 "2008-03-05T17:24:05Z")

</div>

Eva wrote:

> Thank you!

You’re setting the “value” for the radio button to the String  
“color.id”. Take the quotes off and it should work.

\<%= radio\_button(“page”, “color\_id”, color.id) %\>

not

\<%= radio\_button(“page”, “color\_id”, “color.id”) %\>

–  
[http://www.5valleys.com/](http://www.5valleys.com/)  
[http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)

---

<div class="post-metadata">

**Author:** ![Eva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dbc845/32.png) [@Eva](https://www.ruby-forum.com/u/Eva)\
**Post date:** [March 5, 2008, 7:02pm UTC](https://www.ruby-forum.com/t/radio-button-does-not-get-checked/131052/3 "2008-03-05T19:02:06Z")

</div>

Thank you! This was it!!!

---

<div class="post-metadata">

**Author:** ![Eva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dbc845/32.png) [@Eva](https://www.ruby-forum.com/u/Eva)\
**Post date:** [March 5, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/radio-button-does-not-get-checked/131052/4 "2008-03-05T19:09:08Z")

</div>

I have this other problem, that “color\_id” is not a database column it  
is a method that returns an integer on page. But when the button is  
clicked I wand to update the columns paint\_id of the table page. How  
would I do that? I get the error “undefined method”.  
Please help!  
Thank you!

---

<div class="post-metadata">

**Author:** ![Eva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dbc845/32.png) [@Eva](https://www.ruby-forum.com/u/Eva)\
**Post date:** [March 5, 2008, 7:46pm UTC](https://www.ruby-forum.com/t/radio-button-does-not-get-checked/131052/5 "2008-03-05T19:46:35Z")

</div>

Eva wrote:

> I have this other problem, that “color\_id” is not a database column it  
> is a method that returns an integer on page. But when the button is  
> clicked I wand to update the columns paint\_id of the table page. How  
> would I do that? I get the error “undefined method”.  
> Please help!  
> Thank you!

in Page, define the following

def color\_id=(i)  
#do whatever you need to set the value here.  
#the variable _will be the id of the checked box in the submitted  
form  
end_

 

–  
[http://www.5valleys.com/](http://www.5valleys.com/)  
[http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)
