Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Recipe for Awesomeness
- You will need:
- 1 categories controller
- 1 recipes controller
- 1 routes.rb file
- ## In your routes.rb file
- map.resources :categories do |category|
- category.resources :recipes
- end
- ## In your recipes controller
- class RecipesController < ApplicationController
- before_filter :find_category
- #gently stir in the seven restful actions here
- # index, show, new, create, edit, update, destroy
- # example:
- def index
- @recipes = if @category.nil?
- Recipe.find(:all)
- else
- @category.recipes
- end
- end
- private
- def find_category
- @category = Category.find(params[:category_id]) if params[:category_id]
- end
- end
- ## Let set. Enjoy.
Add Comment
Please, Sign In to add comment