Guest User

Untitled

a guest
Nov 12th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. class CommentsController < ApplicationController
  2. before_action :set_comment, only: [:show, :edit, :update, :destroy]
  3.  
  4. # POST /comments
  5. # POST /comments.json
  6. def create
  7. @comment = Comment.new(comment_params)
  8.  
  9. respond_to do |format|
  10. if @comment.save
  11. format.html { redirect_to @comment.post, notice: 'Comment was successfully created.' }
  12. format.json { render :show, status: :created, location: @comment }
  13. else
  14. format.html { render :new }
  15. format.json { render json: @comment.errors, status: :unprocessable_entity }
  16. end
  17. end
  18. end
  19.  
  20. private
  21. # Use callbacks to share common setup or constraints between actions.
  22. def set_comment
  23. @comment = Comment.find(params[:id])
  24. end
  25.  
  26. # Never trust parameters from the scary internet, only allow the white list through.
  27. def comment_params
  28. params.require(:comment).permit(:post_id, :body)
  29. end
  30. end
Add Comment
Please, Sign In to add comment