Skip to content

Instantly share code, notes, and snippets.

@hafizio
Created May 25, 2014 21:16
Show Gist options
  • Save hafizio/79e42b9ea8676701c213 to your computer and use it in GitHub Desktop.
Save hafizio/79e42b9ea8676701c213 to your computer and use it in GitHub Desktop.
MoviesController
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