Last active
October 30, 2018 14:51
-
-
Save lucasmedeirosleite/6626a7be0ecfb2cd7c12eda91f4170de to your computer and use it in GitHub Desktop.
Fat controller
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 | |
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