Form to sort an index in rails

Posted by shmichael on Stack Overflow See other posts from Stack Overflow or by shmichael
Published on 2010-04-19T12:27:54Z Indexed on 2010/04/19 12:43 UTC
Read the original article Hit count: 268

Filed under:
|
|
|

I'm a newcomer to Rails. I want to build a simple form that determines the sort order of a list. I've implemented a form in the likes of -

<%= radio_button_tag :sort, "rating" %>
  <%= label_tag :sort_rating, "order by rating" %>
<%= radio_button_tag :sort, "name" %>
  <%= label_tag :sort_name, "order by name" %>

And now I am unsure how to implement the sort at the controller/model level. The aspects I am puzzled about are:

  • Where should the sort be performed
  • How could the sort parameter be persisted
  • How could the code be reused

Right now, I can't even get the selected sort method to remain selected after a submit.

I would most appreciate any guidance or reference to an example.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about sorting