Created
May 25, 2014 21:16
-
-
Save hafizio/79e42b9ea8676701c213 to your computer and use it in GitHub Desktop.
MoviesController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MoviesController < ApplicationController | |
def show | |
@movie = Movie.find(params[:id]) | |
end | |
def index | |
@all_ratings = Movie.all_ratings | |
if params[:ratings] != nil | |
@movies = Movie.where(rating: params['ratings'].keys) | |
else | |
@movies = Movie.all | |
end | |
end | |
def new | |
# default: render 'new' template | |
end | |
def create | |
@movie = Movie.create!(params[:movie]) | |
flash[:notice] = "#{@movie.title} was successfully created." | |
redirect_to movies_path | |
end | |
def edit | |
@movie = Movie.find(params[:id]) | |
end | |
def update | |
@movie = Movie.find(params[:id]) | |
@movie.update_attributes!(params[:movie]) | |
flash[:notice] = "#{@movie.title} was successfully updated." | |
redirect_to movie_path(@movie) | |
end | |
def destroy | |
@movie = Movie.find(params[:id]) | |
@movie.destroy | |
flash[:notice] = "Movie '#{@movie.title}' deleted." | |
redirect_to movies_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment