Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. class MoviesController < ApplicationController
  2.  
  3. def index
  4. @movies = Movie.all
  5. end
  6. #GET /movies/:id
  7. def show
  8. id = params[:id]
  9. @movie = Movie.find(id)
  10. #render plain: 'show'+params[:id]
  11. end
  12. #POST /movies/
  13. # skip_before_action :verify_autenticity_token:
  14. def create
  15. @movie = Movie.create!(params[:movie].permit(:title, :rating, :description, :realease_date))
  16. flash[:notice] = "#{@movie.title} was successfully created."
  17. redirect_to movies_path
  18. end
  19.  
  20. #new
  21. def new
  22. end
  23.  
  24. def edit
  25. id = params[:id]
  26. @movie = Movie.find(id)
  27. end
  28.  
  29. def update
  30. id = params[:id]
  31. @movie = Movie.find(id)
  32. if @movie.update_attributes!(params[:movie].permit(:title,:rating,:realease_date))
  33. flash[:notice] = "#{@movie.title} has been edited."
  34. redirect_to movies_path
  35. end
  36. end
  37.  
  38. def destroy
  39. id = params[:id]
  40. @movie = Movie.find(id)
  41. @movie.destroy
  42. flash[:notice] = "#{@movie.title} has been deleted."
  43. redirect_to movies_path
  44. end
  45.  
  46.  
  47. end
  48.  
  49. %h2 Details about #{@movie.title}
  50.  
  51. %ul#details
  52. %li
  53. Rating:
  54. = @movie.rating
  55. %li
  56. Released on:
  57. = @movie.realease_date#.strftime("%B %d, %Y")
  58.  
  59. %h3 Description:
  60.  
  61. %p#description= @movie.description
  62.  
  63. %h4 Reviews:
  64.  
  65. - if @movie.reviews.empty?
  66. %p
  67. No reviews for this movie...
  68.  
  69. -else
  70. - @movie.reviews.each do |r|
  71. - u = Moviegoer.find(r.moviegoer_id)
  72. <b>#{r.vote}</b> (<i>#{Moviegoer.find(r.moviegoer_id).name}</i>) #{r.message} <br />
  73.  
  74.  
  75. = link_to 'Add review', new_movie_review_path(@movie)
  76. <br/><br/>
  77.  
  78.  
  79.  
  80. #{link_to 'Edit info', edit_movie_path(@movie)} - #{link_to 'Delete', movie_path(@movie), :method => :delete} - #{link_to 'Back to movie list', movies_path}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement