Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. class AnimalsController < ApplicationController
  2.  
  3. def index
  4. @animals = Animal.all
  5. #@animals = @q.result
  6. #@animals - Animal.where(["owner Like ?","%#{params[:search]}%"])
  7. #@q = Animal.ransack(params[:q])
  8. end
  9. def show
  10. @animals = Animal.find(params[:id])
  11. end
  12. def edit
  13. @animals = Animal.find(params[:id])
  14. end
  15. def update
  16. @animals = Animal.find(params[:id])
  17. if @animals.update(animal_params)
  18. flash[:notice] = "Animal Log Successfully Updated!"
  19. redirect_to @animals
  20. else
  21. render :edit
  22. end
  23. end
  24.  
  25. def new
  26. @animals = Animal.new
  27. end
  28. def create
  29. @animals = Animal.new(animal_params)
  30. @animals.save
  31. redirect_to @animals
  32. end
  33.  
  34. def destroy
  35. @animals = Animal.find(params[:id])
  36. @animals.destroy
  37. redirect_to @animals
  38. end
  39.  
  40. def image_for(animal)
  41. if animal.image_file_name.blank?
  42. image_tag('animals.jpg')
  43. else
  44. image_tag(animal.image_file_name)
  45. end
  46. end
  47. def animal_params
  48. params.require(:animal).permit(:animalname, :owner)
  49. end
  50.  
  51. private
  52.  
  53. def animal_params
  54. params.require(:animal).permit(:datemissing, :owner, :address, :phone, :description, :animalname, :notes, :sex)
  55. end
  56.  
  57.  
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement