Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CommentsController < ApplicationController
- before_action :set_comment, only: [:show, :edit, :update, :destroy]
- # POST /comments
- # POST /comments.json
- def create
- @comment = Comment.new(comment_params)
- respond_to do |format|
- if @comment.save
- format.html { redirect_to @comment.post, notice: 'Comment was successfully created.' }
- format.json { render :show, status: :created, location: @comment }
- else
- format.html { render :new }
- format.json { render json: @comment.errors, status: :unprocessable_entity }
- end
- end
- end
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_comment
- @comment = Comment.find(params[:id])
- end
- # Never trust parameters from the scary internet, only allow the white list through.
- def comment_params
- params.require(:comment).permit(:post_id, :body)
- end
- end
Add Comment
Please, Sign In to add comment