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 == "") %> <%= " " if (prod.send(col.name).to_s == "") %> </td> <% end %> </tr> <% end %> <tr> </table> ----- Thanks. Abbath
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. -- Posted via http://www.ruby-forum.com/.
On 12/30/05, Kevin Olbrich <kevin.olbrich@duke.edu> wrote:> 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.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