# How to give the condition between Id field and name field

**URL:** <https://www.ruby-forum.com/t/how-to-give-the-condition-between-id-field-and-name-field/173009>\
**Category:** Rails\
**Created:** [July 31, 2009, 9:39am UTC](https://www.ruby-forum.com/t/how-to-give-the-condition-between-id-field-and-name-field/173009 "2009-07-31T09:39:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/958977/32.png) [@sts](https://www.ruby-forum.com/u/sts)\
**Post date:** [July 31, 2009, 9:39am UTC](https://www.ruby-forum.com/t/how-to-give-the-condition-between-id-field-and-name-field/173009/1 "2009-07-31T09:39:33Z")

</div>

Hi,  
Am having a table with quetion\_id , nominees and vote\_count. In which  
the values for question\_id and nominees are prepopulated from other  
tables with vote\_count as zero.

If the users select some nominees the vote count should be incresed by  
one. The problem is How to connect the question\_id and nominees like for  
this question\_id this nominee is selected .

can some one give example for this situation…

---

<div class="post-metadata">

**Author:** ![sts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/958977/32.png) [@sts](https://www.ruby-forum.com/u/sts)\
**Post date:** [July 31, 2009, 3:40pm UTC](https://www.ruby-forum.com/t/how-to-give-the-condition-between-id-field-and-name-field/173009/2 "2009-07-31T15:40:58Z")

</div>

If your table looked like:  
question\_id  
nominee\_id  
vote\_count

Then a voting page could populate a droplist with the ids and names of  
the nominees (the default should be something other than the first  
nominee to reduce ‘laziness bias’ in the results). The user chooses an  
entry and submits.

The controller then takes the post, grabs the question\_id, selected  
nominee id and updates the vote\_count for that record.

You could go another route an populate a form with radiobuttons, one per  
nominee, but you’ll need to read up on radiobuttons in forms for Rails  
as you code is a bit more involved (you’ll be passing an array to the  
form, and pulling the one ‘selected’ option out of that list in your  
controller.
