Skip to content

Instantly share code, notes, and snippets.

@radar
Forked from leofrozenyogurt/gist:5308094
Created April 4, 2013 05:43
Show Gist options
  • Save radar/5308101 to your computer and use it in GitHub Desktop.
Save radar/5308101 to your computer and use it in GitHub Desktop.
class CommentsController < ApplicationController
def index
@commentable = Video.find(params[:video_id])
@comments = @commentable.comments
end
def new
@commentable = Video.find(params[:video_id])
@comment = @commentable.comments.new
end
def create
@commentable = Video.find(params[:video_id])
@comment = @commentable.comments.new(params[:comment])
@comment.user_id= current_user.id
if @comment.save
redirect_to @commentable, notice: "Comment created."
else
render :new
end
end
def destroy
@comment = Comment.find(params[:id])
@commentable = @comment.commentable
if @comment.destroy
redirect_to @commentable
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment