dmitriy-kiriyenko/hw2_rottenpotatoes — pull request #1 by dmitriy-kiriyenko (2012-03-08 16:04:56+00:00)
Title: Homework 2 - task 3b

RottenPotatoes enhancement #1: Sorting the list of all movies.
Enhance RP in the following way:

On the list of all movies page, the column headings for 'title' and
'release date' for a movie should be clickable links. Clicking one of
them should cause the list to be reloaded but sorted in ascending
order on that column. For example, clicking the 'release date' column
heading should redisplay the list of movies with the earliestreleased
movies first; clicking the 'title' field should list the movies
alphabetically by title. (For movies whose names begin with
non-letters, the sort order should match the behavior of String#<=>.)

* IMPORTANT for grading purposes:
* The link (that is, the `` tag) for sorting by ‘title’ should have
the HTML element id `title_header`.
* The link for sorting by ‘release date’ should have the HTML element
id `release_date_header`.
* The table containing the list of movies should have the HTML
element id movies (this has already been set for you by existing code).
* When the listing page is redisplayed with sorting-on-a-column
enabled, the column header that was selected for sorting should
appear with a yellow background, as shown below. You should do this by
setting controller variables that are used to conditionally set the
CSS class of the appropriate table heading to `hilite`, and pasting
this simple CSS into RottenPotatoes'
`app/assets/stylesheets/application.css file`.

```css
table#movies th.hilite {
background-color: yellow;
}
```

![](http://i.minus.com/i1eerJPsqTD6e.png)

Here are some hints and caveats as you do this part:
* The current RottenPotatoes views use the Rails-provided "resourceful
routes" helper `movies_path` to generate the correct URI for the
movies index page. You may find it helpful to know that if you pass
this helper method a hash of additional parameters, those parameters
will be parsed by Rails and available in the params[] hash.
* Databases are pretty good at returning collections of rows in sorted
order according to one or more attributes. Before you rush to sort
the collection returned from the database, look at the documentation
for the ActiveRecord find and all methods and see if you can get the
database to do the work for you.
* Don't put code in your views! The view shouldn't have to sort the
collection itself—its job is just to show stuff. The controller
should spoon-feed the view exactly what is to be displayed.