The ban on the edit and delete comment in Rails Devise the problem with the access?

This question, I want to make a ban on editing someone else's comment, but it turns out that even his can't edit or delete, here is the controller code comment
class CommentsController < ApplicationController
 before_action :authenticate_user!, except: [:index, :show]

 def create
@post=Post.find(params[:post_id])
 @comment = @post.comments.new(comment_params.merge(user_id: current_user.id))

 if @comment.save
 redirect_to post_path(@post)
else
 render :edit
end
end
 def destroy
 @post = Post.find(params[:post_id])
@post.comments.find(params[:id]).destroy
 redirect_to post_path(@post)
end
def update
@post = Post.find(params[:post_id])
@comment = @post.comments.find(params[:id])

if (@comment.update(comment_params))
redirect_to post_path(@post)
else
render 'edit'
end
end


 def edit
 @post = Post.find(params[:post_id]) 
 if @post.comments==current_user.id
 @comment = @post.comments.find(params[:id])
else
 redirect_to @post
end

 end 


 private def comment_params 
 params.require(:comment).permit(:username, :body, :image) 
end
end
March 19th 20 at 08:32
1 answer
March 19th 20 at 08:34
@post.comments==current_user.id - why do you object with value compare?
I don't know how to do. - lela_Kuhic98 commented on March 19th 20 at 08:37
@lela_Kuhic98, then I would advise you to read the documentation and examples rusrails.ru/.
Ruby ucbenik to read.

If you get to Devise, such things you have to understand, if missed, it is best to read the tutorial.
Poprobovatj suggest to use the rubymine debugger in it, it will also help you find the answer. - Brendon_Gerho commented on March 19th 20 at 08:40

Find more questions by tags Ruby on Rails