Route structure for multiple associations in Rails I'm doing a site at the moment (first Rails site, learning as I code) and I'm concerned that I'm over complicating the routes.

My associations boil down to:

class Recipe &lt; ActiveRecord::Base
    has_and_belongs_to_many :categories
    belongs_to :book
end

class Category &lt; ActiveRecord::Base
    belongs_to :category_type
    has_and_belongs_to_many :recipes    
end

class Book &lt; ActiveRecord::Base
  has_many :recipes
end


I want to end up with URLs like this:

/books/3/recipes  #to show all recipes from book 3
/category/12/recipes #to show all categories from category 12
/recipes/3  #to show recipe 3


The good news is I have this all working, but in the course of doing so I feel like I may have strayed a little from "the Rails way" and I was wondering if someone could take a look and let me know if I've gone wrong. The bits I'm particularly concerned about are my routes.rb file (because I appear to be repeating myself):

resources :books do
  resources :recipes
end

resources :categories do
  resources :recipes
end


In particular, the recipes#index action, which seems a little verbose:

def index

  if(params[:category_id])
    @recipes = Recipe.find_by_category(params[:category_id])
  elsif(params[:book_id])
    @recipes = Recipe.where(:book_id =&gt; params[:book_id])
  else
    @recipes = Recipe.find(:all)
  end
end


Now, it might be that this is all absolutely fine, but I just want to check before I get too much further in!
This is probably fine, though there are other ways to do it like passing filters to /recipes (?category_id=x or ?book_id=x). Your controller action is probably fine too, though I may have considered making multiple controllers. 

Though i'm not sure why you're doing find_by_category instead of the a find_all_by_category or the same .where as you're doing for book_id. Also, Recipe.all is more rails 3.