@Mydrug

Запрет на редактирования и удаления комментария в Rails в Devise проблема с доступом?

Такой вопрос, хочу сделать запрет на редактирования чужого комментария, но получается так, что даже свой не могу отредактировать или удалит, вот код контроллера 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
  • Вопрос задан
  • 57 просмотров
Пригласить эксперта
Ответы на вопрос 1
alfss
@alfss
https://career.habr.com/alfss
@post.comments==current_user.id - а зачем вы объект со значением сравниваете?
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы