Skip to content

Instantly share code, notes, and snippets.

@lucasmedeirosleite
Last active October 30, 2018 14:51
Show Gist options
  • Save lucasmedeirosleite/6626a7be0ecfb2cd7c12eda91f4170de to your computer and use it in GitHub Desktop.
Save lucasmedeirosleite/6626a7be0ecfb2cd7c12eda91f4170de to your computer and use it in GitHub Desktop.
Fat controller
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(comment_params)
@comment.user_id = current_user.id if current_user
if @comment.save
StatusWorker.perform_aync(@comment.id)
NotifyChannelsWorker.perform_async(@comment.id)
AuthorMailer.notify_mail(@post.author.id).deliver_later
redirect_to post_path(@post)
else
render 'new'
end
end
def edit
@post = Post.find(params[:post_id])
@comment = @post.comments.find(params[:id])
end
def update
@post = Post.find(params[:post_id])
@comment = @post.comments.find(params[:id])
if @comment.update(params[:comment].permit(:comment))
redirect_to post_path(@post)
else
render 'Edit'
end
end
def destroy
@post = Post.find(params[:post_id])
@comment = @post.comments.find(params[:id])
@comment.destroy
redirect_to post_path(@post)
end
private
def comment_params
params.require(:comment).permit(:comment)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment