Best practice for sorting data in a Rails app -


I always list objects in an 'index' method. What is the best practice to tackle sorting for this? So in the scene I want a dropdown that lets me choose through [created, size, value, ...]. An example would be greatly appreciated.

I see it as one of the best practice practices of applicability.

The answer really depends on how information is displayed. Along with this, there is so much in it.

If all the information that can be sorted by the user is displayed on the page in the table form, then I will only use link_to_remote to update the table with new sorting.

If your list has to sort different criteria for a long time, then you probably will paging some kind of paging. Then this example will be used.

Controller

  DIF Index Order = Parameters [: Order] Search_option = {: per_page = & gt; Param [: per_page] || 20 ,: Page = & gt; Param [: per_page] || 1),: Order = & gt; Order} @tings = things.paginate (find_options) response_to do | Format | Format.html # default action # Action Only a table partial update if the action is a Java Script request: Format.js render: update | Page | Page.replace_html: things_table_body ,: partial = & gt; Things, Collections = & gt; @ Thing and End  

It is not meant to do this without partiality.

See:

  ...  & Lt; / Table & gt; & Lt;% = will_paginate @ things% & gt; ...  

The href option in link_to_remote allows fallback to html requests in the event that your user does not have javascript enabled.

Things Partial:

  & lt; Tr & gt; & Lt; TD & gt; & Lt;% = thing.name% & gt; & Lt; / TD & gt; & Lt; TD & gt; & Lt;% = thing.created_at% & gt; & Lt; / TD & gt; & Lt; / TR & gt;  

It has been left as a practice to learn how to toggle the reader in ascending or descending sorting.

In this event you are not listing all the specialties a selection box is OK. Personally, I used to go for radio buttons, if the list of sorting methods is not too long

Anyhow the controller code that I previously posted looks almost identical Will give

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -