Guest User

Untitled

a guest
Jun 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. class RecipesController > ApplicationController
  2. def index
  3. list
  4. render :action => 'list'
  5. end
  6.  
  7. verify :method => :post, :only => [ :destroy, :create, :update ],
  8. :redirect_to => { :action => :list }
  9.  
  10. def list
  11. @recipe_pages, @recipes = paginate :recipes, :per_page => 10
  12. end
  13.  
  14. def show
  15. @recipe = Recipe.find(params[:id])
  16. end
  17.  
  18. def new
  19. @recipe = Recipe.new
  20. end
  21.  
  22. def create
  23. @recipe = Recipe.new(params[:recipe])
  24. if @recipe.save
  25. flash[:notice] = 'Recipe was successfully created.'
  26. redirect_to :action => 'list'
  27. else
  28. render :action => 'new'
  29. end
  30. end
  31.  
  32. def edit
  33. @recipe = Recipe.find(params[:id])
  34. end
  35.  
  36. def update
  37. @recipe = Recipe.find(params[:id])
  38. if @recipe.update_attributes(params[:recipe])
  39. flash[:notice] = 'Recipe was successfully updated.'
  40. redirect_to :action => 'show', :id => @recipe
  41. else
  42. render :action => 'edit'
  43. end
  44. end
  45.  
  46. def destroy
  47. Recipe.find(params[:id]).destroy
  48. redirect_to :action => 'list'
  49. end
  50. end
Add Comment
Please, Sign In to add comment