Skip to content

Instantly share code, notes, and snippets.

@chintanparikh
Created November 5, 2014 23:50
Show Gist options
  • Save chintanparikh/9841209f5c96564efed2 to your computer and use it in GitHub Desktop.
Save chintanparikh/9841209f5c96564efed2 to your computer and use it in GitHub Desktop.
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
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