# Radiobutton onclick

**URL:** <https://www.ruby-forum.com/t/radiobutton-onclick/54926>\
**Category:** Rails\
**Created:** [December 30, 2005, 11:52am UTC](https://www.ruby-forum.com/t/radiobutton-onclick/54926 "2005-12-30T11:52:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abbath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@Abbath](https://www.ruby-forum.com/u/Abbath)\
**Post date:** [December 30, 2005, 11:52am UTC](https://www.ruby-forum.com/t/radiobutton-onclick/54926/1 "2005-12-30T11:52:10Z")

</div>

Hi,

I would like to make a simple html which displays the contents of a  
table from a database. So I put radiobuttons near the titles of the  
columns to note and do a sorting by that column. But I don’t know how  
to implement that the clicking on one of the radiobuttons make the  
sorting. The problem is the view part. How to give a radiobutton to  
make some action on a click by the helper?

The code is:

* * *
 \<% for col in Product.content\_columns %\> \<% end%\> \<% for prod in @product %\> \<% for col in Product.content\_columns %\> \<% end %\> \<% end %\> 

| \<%= radio\_button :index, 'head', col.name %\>\<%= col.name %\> |
| \<%= prod.send(col.name) unless (prod.send(col.name).to\_s == "") %\> \<%= "&nbsp;" if (prod.send(col.name).to\_s == "") %\> |
|
| |

-----

Thanks.

Abbath

---

<div class="post-metadata">

**Author:** ![Abbath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@Abbath](https://www.ruby-forum.com/u/Abbath)\
**Post date:** [December 30, 2005, 3:14pm UTC](https://www.ruby-forum.com/t/radiobutton-onclick/54926/2 "2005-12-30T15:14:42Z")

</div>

Abbath wrote:

> Hi,
> 
> I would like to make a simple html which displays the contents of a  
> table from a database. So I put radiobuttons near the titles of the  
> columns to note and do a sorting by that column. But I don’t know how  
> to implement that the clicking on one of the radiobuttons make the  
> sorting. The problem is the view part. How to give a radiobutton to  
> make some action on a click by the helper?

Another approach you can use that avoids radio buttons would be to make  
the title of each column a hyperlink with a ‘sort’ param.

\<%= link\_to ‘Column1’, :action=\>‘list’, :sort=\>‘column1’ %\>

Then have the ‘list’ action pick up the ‘sort’ param and use that in  
your find or paginate ( :order =\> :sort, I think).

This basically forces the database to return the results in the sorted  
order and then re-displays it.

There are a bunch of AJAXy ways to do the same thing that look nicer,  
but this is an easy solution.

\_Kevin

disclaimer… this was all out of my head, so some of the coding may  
need to be tweaked.

---

<div class="post-metadata">

**Author:** ![Abbath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@Abbath](https://www.ruby-forum.com/u/Abbath)\
**Post date:** [December 31, 2005, 1:01am UTC](https://www.ruby-forum.com/t/radiobutton-onclick/54926/3 "2005-12-31T01:01:40Z")

</div>

On 12/30/05, Kevin O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Another approach you can use that avoids radio buttons would be to make  
> There are a bunch of AJAXy ways to do the same thing that look nicer,  
> but this is an easy solution.
> 
> \_Kevin
> 
> disclaimer… this was all out of my head, so some of the coding may  
> need to be tweaked.

Kevin, I was lurking on the your answer. It will make my app more  
usefull. Thanks.

FYI – :order =\> :sort is actually :order =\> params[:sort]

## Thanks again, Greg

Greg F.  
The Norcross Group  
Forensics for the 21st Century
