Guest User

Untitled

a guest
Apr 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. ## Recipe for Awesomeness
  2.  
  3. You will need:
  4. 1 categories controller
  5. 1 recipes controller
  6. 1 routes.rb file
  7.  
  8. ## In your routes.rb file
  9.  
  10. map.resources :categories do |category|
  11. category.resources :recipes
  12. end
  13.  
  14. ## In your recipes controller
  15.  
  16. class RecipesController < ApplicationController
  17. before_filter :find_category
  18.  
  19. #gently stir in the seven restful actions here
  20. # index, show, new, create, edit, update, destroy
  21.  
  22. # example:
  23.  
  24. def index
  25. @recipes = if @category.nil?
  26. Recipe.find(:all)
  27. else
  28. @category.recipes
  29. end
  30. end
  31.  
  32. private
  33. def find_category
  34. @category = Category.find(params[:category_id]) if params[:category_id]
  35. end
  36. end
  37.  
  38. ## Let set. Enjoy.
Add Comment
Please, Sign In to add comment