# Sorting in REST

**URL:** <https://discuss.rubyonrails.org/t/sorting-in-rest/23226>\
**Category:** rubyonrails-talk\
**Created:** [January 15, 2008, 4:42am UTC](https://discuss.rubyonrails.org/t/sorting-in-rest/23226 "2008-01-15T04:42:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sumeru](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@Sumeru](https://discuss.rubyonrails.org/u/Sumeru)\
**Post date:** [January 15, 2008, 4:42am UTC](https://discuss.rubyonrails.org/t/sorting-in-rest/23226/1 "2008-01-15T04:42:35Z")

</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:** ![Wildtangent](https://avatars.discourse-cdn.com/v4/letter/w/df788c/32.png) [@Wildtangent](https://discuss.rubyonrails.org/u/Wildtangent)\
**Post date:** [January 15, 2008, 7:39pm UTC](https://discuss.rubyonrails.org/t/sorting-in-rest/23226/2 "2008-01-15T19:39:16Z")

</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 &nbsp;&nbsp;&nbsp;&nbsp;@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
