Given I have two models: `company` and `location`. A `company` has many `locations`.  

I found [Ryan Bates' Named Routes](http://railscasts.com/episodes/34-named-routes) very interesting.  

So I added resources for each of my model in `routes.rb`.

```
resources :companies
resources :locations

```

This enables me to generate links based on named routes like `<%= link_to "Companies", companies_path %>` which results in `http://localhost:3000/companies`.

Now I want to filter the list of `locations` based on the `company` they belong to. Before working with named routes I accomplished this by add a link like the following.

```
<%= link_to "Locations for this company", { :controller => 'locations', :action => 'list', :company_id => company.id } %>

```

Here I pass the `company_id` to the `LocationsController` which filters the location in its `list` action.

```
def list
  @locations = Location.order("locations.id ASC").where(:company_id => @company.try(:id))
end

```