# Sorting in REST

**URL:** <https://www.ruby-forum.com/t/sorting-in-rest/126067>\
**Category:** Rails\
**Created:** [January 15, 2008, 5:43am UTC](https://www.ruby-forum.com/t/sorting-in-rest/126067 "2008-01-15T05:43:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sumeru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@Sumeru](https://www.ruby-forum.com/u/Sumeru)\
**Post date:** [January 15, 2008, 5:43am UTC](https://www.ruby-forum.com/t/sorting-in-rest/126067/1 "2008-01-15T05:43:22Z")

</div>

I have written the following code for sorting list of courses:

\<%= link\_to\_remote “From Date”, :update =\> ‘content’, :url =\>  
{:controller=\> “courses”, :action =\> ‘list’, :sort =\>  
‘from\_date’ }, :before =\> “Element.show(‘loading’)”, :complete =\>  
“Element.hide(‘loading’)”, :method =\> ‘get’ %\>

I want to change above code to REST architecture, I changed the url to  
courses\_path, :sort =\>'from\_date. Its not working.

Can u help me to make it in RESTful way.

---

<div class="post-metadata">

**Author:** ![Sumeru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@Sumeru](https://www.ruby-forum.com/u/Sumeru)\
**Post date:** [January 15, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/sorting-in-rest/126067/2 "2008-01-15T20:40:01Z")

</div>

\<%= link\_to\_remote “From Date”, :update =\> ‘content’, :url =\>  
courses\_path(:sort =\> ‘from\_date’), :method =\> :get, :before =\>  
"Element.show(‘loading’), :complete =\> “Element.hide(‘loading’)” %\>

in controller, change the ‘list’ action to be ‘index’. List is not  
used by the REST defaults

def index  
@courses.find(:all, :order =\> params[:sort])  
end

in your routes make sure you have

map.resources :courses

Don’t forget your checking when bringing in the params[:sort]  
parameter

If you need custom routes for your REST app do this, but think about  
the requirement first (it’s not a bad thing to do when you need it,  
but often you don’t need it):

map.resources :courses, :collection = {:list\_tagged =\> :get}, :member  
=\> {:enable =\> :put}

etc. Collection takes the pluralised controller name plus the method  
you define, e.g. courses\_search\_path = ‘/courses/search’  
member takes the controller, plus a record selected by id, e.g.  
course\_enable\_path(@course) = /courses/1/enable
