# Re: radio\_button\_tag

**URL:** <https://www.ruby-forum.com/t/re-radio-button-tag/116945>\
**Category:** Rails\
**Created:** [October 11, 2007, 3:09pm UTC](https://www.ruby-forum.com/t/re-radio-button-tag/116945 "2007-10-11T15:09:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 11, 2007, 3:09pm UTC](https://www.ruby-forum.com/t/re-radio-button-tag/116945/1 "2007-10-11T15:09:53Z")

</div>

Hi

Radio buttons need to belong to the same group to be able to work  
together. In your code you have two different groups, or attributes,  
:actuel and :last. These need to be the same - the general form of the  
radio\_button\_tag helper is:  
radio\_button\_tag(:attribute, tag\_value, options). You can then determine  
which one was pressed when the form is submitted by the value of the  
button given in the params hash

HTH

Clive

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 11, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/re-radio-button-tag/116945/2 "2007-10-11T15:28:15Z")

</div>

unknown wrote:

> Hi
> 
> Radio buttons need to belong to the same group to be able to work  
> together. In your code you have two different groups, or attributes,  
> :actuel and :last. These need to be the same - the general form of the  
> radio\_button\_tag helper is:  
> radio\_button\_tag(:attribute, tag\_value, options). You can then determine  
> which one was pressed when the form is submitted by the value of the  
> button given in the params hash
> 
> HTH
> 
> Clive

Hello

Thanks for your answer.

I had put the radio buttons with the same name to be on the same group.

actuel \<%= radio\_button\_tag(:type\_recherche, value = "1", checked = false, options = {}) %\> last \<%= radio\_button\_tag(:type\_recherche, value = "2", checked = false, options = {}) %\>

To pass the values I use a link\_to\_remote:

\<%= link\_to\_remote “Rechercher”,  
:update =\> “resultlist”,  
:url =\> { :action =\> ‘rechercher’},  
:with =\> “…+ ‘&’ +  
‘type\_recherche=’ + $F(‘type\_recherche’)”,  
:complete =\> visual\_effect(:appear, ‘resultlist’, :duration =\> 1.00)  
%\>

In my controller when i try to access to the “type\_recherche” value (my  
2 radio buttons), I do this:

if params[:type\_recherche].nil?  
puts “1”  
@demand.type\_recherche = “0”  
else  
if params[:type\_recherche].to\_s == ‘null’  
@demand.type\_recherche = “0”  
else  
puts "6 -\> " + params[:type\_recherche].to\_s  
@demand.type\_recherche = params[:type\_recherche]  
end  
end

When i check the first radio it works fine. I receive the value “1”. But  
when i check the second radio button, i always receive null. It seems  
that the only radio button used is the first one.

Any idea about this problem.

Thanks
