Created
November 5, 2014 23:50
-
-
Save chintanparikh/9841209f5c96564efed2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 VideosController < ApplicationController | |
respond_to :html, :json | |
before_action :get_video, only: [:show, :update, :destroy] | |
def index | |
@videos = Video.all | |
respond_with @videos | |
end | |
def create | |
@video = Video.new(video_params) | |
if @video.save | |
render json: @video, status: :ok | |
else | |
render json: {video: @video.errors, status: :no_content} | |
end | |
end | |
def show | |
respond_with @video | |
end | |
def update | |
if @video.update_attributes(video_params) | |
render json: @video, status: :ok | |
else | |
render json: {video: @video.errors, status: :unprocessable_entity} | |
end | |
end | |
def destroy | |
@video.destroy | |
render json: {status: :ok} | |
end | |
private | |
def video_params | |
params.fetch(:video, {}).permit(:video_url, :team, :season, :event, :school) | |
end | |
def get_video | |
@video = Video.find(params[:id]) | |
render json: {status: :not_found} unless @video | |
end | |
end |
This file contains hidden or 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 CreateVideos < ActiveRecord::Migration | |
def change | |
create_table :videos do |t| | |
t.string :video_url | |
t.string :team | |
t.string :season | |
t.string :event | |
t.string :school | |
t.integer :placement, default: nil | |
t.timestamps null: false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment