docbrown/app/controllers/admin/comments_controller.rb
Andy Zhao f5913399aa Allow changing user for comments in admin panel (#113)
* Allow changing user for comments in admin panel

* Add successful flash msg

* Use user_id instead of name for comment admin
2018-03-20 16:25:09 -04:00

21 lines
608 B
Ruby

module Admin
class CommentsController < Admin::ApplicationController
def update
comment = Comment.find(params[:id])
if comment.update(comment_params)
flash[:notice] = "Comment successfully updated"
redirect_to "/admin/comments/#{comment.id}"
else
flash.now[:error] = comment.errors.full_messages
render :new, locals: { page: Administrate::Page::Form.new(dashboard, comment) }
end
end
private
def comment_params
accessible = %i[user_id body_markdown deleted]
params.require(:comment).permit(accessible)
end
end
end