Skip to content

Instantly share code, notes, and snippets.

@isasi88
Created June 30, 2014 09:26
Show Gist options
  • Save isasi88/4ab709bac9fd3f8fd8af to your computer and use it in GitHub Desktop.
Save isasi88/4ab709bac9fd3f8fd8af to your computer and use it in GitHub Desktop.
class CommentsController < ApplicationController
before_filter :load_commentable
def index
@comments = @commentable.comments
end
def new
@comment = @commentable.comments.new
end
def create
@comment = @commentable.comments.new(comment_params)
if @comment.save
redirect_to @commentable, notice: "Comment created."
else
render :new
end
end
private
def load_commentable
if params[:photo_id]
@commentable = Photo.friendly.find(params[:photo_id])
@user = User.friendly.find(params[:user_id])
end
end
def comment_params
params.require(:comment).permit(:photo_id, :photo, :user, :user_id, :content)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment