Created
June 30, 2014 09:26
-
-
Save isasi88/4ab709bac9fd3f8fd8af to your computer and use it in GitHub Desktop.
This file contains 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 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