Migrate title attribute from rentable to video (and later, game)
[cs356-p2-videostore.git] / app / controllers / video_controller.rb
1 class VideoController < ApplicationController
2   def index
3     list
4     render :action => 'list'
5   end
6
7   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
8   verify :method => :post, :only => [ :destroy, :create, :update ],
9          :redirect_to => { :action => :list }
10
11   def list
12     @video_pages, @videos = paginate :videos, :per_page => 10
13   end
14
15   def show
16     @video = Video.find(params[:id])
17   end
18
19   def new
20     @video = Video.new
21   end
22
23   def create
24     @rentable = Rentable.new
25     @rentable.save!
26     puts "created new rentable with ID: #{@rentable.id}"
27     @video = Video.new(params[:video])
28     @video.rentable_id = @rentable.id
29     if @video.save
30       flash[:notice] = 'Video was successfully created.'
31       redirect_to :action => 'list'
32     else
33       render :action => 'new'
34     end
35   end
36
37   def edit
38     @video = Video.find(params[:id])
39   end
40
41   def update
42     @video = Video.find(params[:id])
43     if @video.update_attributes(params[:video])
44       flash[:notice] = 'Video was successfully updated.'
45       redirect_to :action => 'show', :id => @video
46     else
47       render :action => 'edit'
48     end
49   end
50
51   def destroy
52     Video.find(params[:id]).destroy
53     redirect_to :action => 'list'
54   end
55 end