Forum: Ruby on Rails Radiobutton onclick

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
80545dc99200b5b3ce28f599973a95ec?d=identicon&s=25 Abbath (Guest)
on 2005-12-30 11:52
(Received via mailing list)
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:

-----
<table border="1">
        <tr>
                <% for col in Product.content_columns %>
                <td width="100"><%= radio_button :index, 'head',
col.name %><%= col.name %></td>
                <% end%>
        </tr>
        <% for prod in @product %>
                <tr>
                        <% for col in Product.content_columns %>
                                <td>
                                        <%= prod.send(col.name) unless
(prod.send(col.name).to_s == "") %>
                                        <%= "&nbsp;" if
(prod.send(col.name).to_s == "") %>
                                </td>
                        <% end %>
                </tr>
        <% end %>
        <tr>
</table>
-----

Thanks.

Abbath
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (Guest)
on 2005-12-30 15:14
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.
25bbc96d9c53647354cb724e744b2222?d=identicon&s=25 Greg Freemyer (Guest)
on 2005-12-31 01:01
(Received via mailing list)
On 12/30/05, Kevin Olbrich <kevin.olbrich@duke.edu> 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 Freemyer
The Norcross Group
Forensics for the 21st Century
This topic is locked and can not be replied to.