Guest User

Untitled

a guest
Aug 14th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. class DogsController < ApplicationController
  2. before_action :current_dog, only: [:show, :edit, :update, :destroy]
  3.  
  4. def index
  5. @dogs = Dog.all
  6. end
  7.  
  8. def show
  9.  
  10. end
  11.  
  12. def new
  13. @dog = Dog.new
  14. end
  15.  
  16. def create
  17. dog = Dog.create(dog_params)
  18.  
  19. redirect_to dog_path(dog)
  20. end
  21.  
  22. def edit
  23.  
  24. end
  25.  
  26. def update
  27. current_dog.update(dog_params)
  28.  
  29. redirect_to dog_path(current_dog)
  30. end
  31.  
  32. def destroy
  33. current_dog.destroy
  34.  
  35. redirect_to dogs_path
  36. end
  37.  
  38. private
  39.  
  40. def dog_params
  41. params.require(:dog).permit(:name, :motto)
  42. end
  43.  
  44. def current_dog
  45. @dog = Dog.find(params[:id])
  46. end
  47.  
  48. end
Add Comment
Please, Sign In to add comment