# Radio\_button not updating the database

**URL:** <https://www.ruby-forum.com/t/radio-button-not-updating-the-database/172496>\
**Category:** Rails\
**Created:** [July 22, 2009, 12:34pm UTC](https://www.ruby-forum.com/t/radio-button-not-updating-the-database/172496 "2009-07-22T12:34:56Z")\
**Posts on this page:** 6\
**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 22, 2009, 12:34pm UTC](https://www.ruby-forum.com/t/radio-button-not-updating-the-database/172496/1 "2009-07-22T12:34:56Z")

</div>

Hi,  
Am creating a survey, in which am getting the questions from question  
table and answers from answers table.  
In the survey table am displaying the questions with the answers as  
multiple choice using radio buttons.  
Also while selcting the option the vote\_count should be increased.

The front end part is working correctly, it shows as per my requirement.  
but no values are updated in the database.

\<%=radio\_button(:nominees, count, :onclick =\>  
@voting.increment!(‘vote\_count’) ) %\> \<%= response.nomination %\>  
i want to store the selected values in nominees attribute and want to  
increase the vote\_count by selecting the option.  
any help or advice reg this would be very helpful.

---

<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 22, 2009, 12:50pm UTC](https://www.ruby-forum.com/t/radio-button-not-updating-the-database/172496/2 "2009-07-22T12:50:16Z")

</div>

Tamilselvi Srinivasan wrote:

> Hi,  
> Am creating a survey, in which am getting the questions from question  
> table and answers from answers table.  
> In the survey table am displaying the questions with the answers as  
> multiple choice using radio buttons.  
> Also while selcting the option the vote\_count should be increased.
> 
> The front end part is working correctly, it shows as per my requirement.  
> but no values are updated in the database.
> 
> \<%=radio\_button(:nominees, count, :onclick =\>  
> @voting.increment!(‘vote\_count’) ) %\> \<%= response.nomination %\>  
> i want to store the selected values in nominees attribute and want to  
> increase the vote\_count by selecting the option.  
> any help or advice reg this would be very helpful.

Keep a default value in the answer table for this particular field  
instead of keeping it NULL

Kannan  
[http://www.classifieds.org.in](http://www.classifieds.org.in)

---

<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 22, 2009, 1:13pm UTC](https://www.ruby-forum.com/t/radio-button-not-updating-the-database/172496/3 "2009-07-22T13:13:27Z")

</div>

Tried with that, no change.

> Keep a default value in the answer table for this particular field  
> instead of keeping it NULL
> 
> Kannan  
> [http://www.classifieds.org.in](http://www.classifieds.org.in)

---

<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 22, 2009, 1:22pm UTC](https://www.ruby-forum.com/t/radio-button-not-updating-the-database/172496/4 "2009-07-22T13:22:17Z")

</div>

Tamilselvi Srinivasan wrote:

> Tried with that, no change.
> 
> > Keep a default value in the answer table for this particular field  
> > instead of keeping it NULL
> > 
> > Kannan  
> > [http://www.classifieds.org.in](http://www.classifieds.org.in)

\<%= radio\_button yourmodel, model-attribute, value, :onclick=\>something  
%\>

---

<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 22, 2009, 2:05pm UTC](https://www.ruby-forum.com/t/radio-button-not-updating-the-database/172496/5 "2009-07-22T14:05:37Z")

</div>

On Jul 22, 12:31 pm, Tamilselvi Srinivasan \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> Thanks for the quick reply,  
> Am getting the radio button options from answers table. also its a group  
> of radio buttons.  
> so the count means for the radio\_button id. if i change the count as  
> follows
> 
> \<%=radio\_button(:survey, :nominees, count, :onclick =\>  
> @voting.increment!(‘vote\_count’) ) %\> \<%= response.nomination %\>

the onclick option needs to be a fragment of javascript. Right now you  
are calling @voting.increment! at the point that the template is  
rendered.

Fred

---

<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 22, 2009, 1:31pm UTC](https://www.ruby-forum.com/t/radio-button-not-updating-the-database/172496/6 "2009-07-22T13:31:42Z")

</div>

Thanks for the quick reply,  
Am getting the radio button options from answers table. also its a group  
of radio buttons.  
so the count means for the radio\_button id. if i change the count as  
follows

\<%=radio\_button(:survey, :nominees, count, :onclick =\>  
@voting.increment!(‘vote\_count’) ) %\> \<%= response.nomination %\>

i cant select the option for each question. i can only select one  
option for the whole survey.

Rails L. wrote:

> Tamilselvi Srinivasan wrote:
> 
> > Tried with that, no change.
> > 
> > > Keep a default value in the answer table for this particular field  
> > > instead of keeping it NULL
> > > 
> > > Kannan  
> > > [http://www.classifieds.org.in](http://www.classifieds.org.in)
> 
> \<%= radio\_button yourmodel, model-attribute, value, :onclick=\>something  
> %\>
