Class: Showtube::VideosController

Inherits:
ApplicationController show all
Defined in:
app/controllers/showtube/videos_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /videos POST /videos.json



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/showtube/videos_controller.rb', line 43

def create
  @video = Video.new(params[:video])
  
  respond_to do |format|
    if @video.save
      format.html { redirect_to @video, notice: 'Video was successfully created.' }
      format.json { render json: @video, status: :created, location: @video }
    else
      format.html { render action: "new" }
      format.json { render json: @video.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /videos/1 DELETE /videos/1.json



75
76
77
78
79
80
81
82
83
# File 'app/controllers/showtube/videos_controller.rb', line 75

def destroy
  @video = Video.find(params[:id])
  @video.destroy
  
  respond_to do |format|
    format.html { redirect_to videos_url }
    format.json { head :no_content }
  end
end

#editObject

GET /videos/1/edit



37
38
39
# File 'app/controllers/showtube/videos_controller.rb', line 37

def edit
  @video = Video.find(params[:id])
end

#indexObject

GET /videos GET /videos.json



5
6
7
8
9
10
11
12
# File 'app/controllers/showtube/videos_controller.rb', line 5

def index
  @videos = Video.all
  
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @videos }
  end
end

#newObject

GET /videos/new GET /videos/new.json



27
28
29
30
31
32
33
34
# File 'app/controllers/showtube/videos_controller.rb', line 27

def new
  @video = Video.new
  
  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @video }
  end
end

#showObject

GET /videos/1 GET /videos/1.json



16
17
18
19
20
21
22
23
# File 'app/controllers/showtube/videos_controller.rb', line 16

def show
  @video = Video.find(params[:id])
  
  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @video }
  end
end

#updateObject

PUT /videos/1 PUT /videos/1.json



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/showtube/videos_controller.rb', line 59

def update
  @video = Video.find(params[:id])
  
  respond_to do |format|
    if @video.update_attributes(params[:video])
      format.html { redirect_to @video, notice: 'Video was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @video.errors, status: :unprocessable_entity }
    end
  end
end