posts_controller.rb 销毁方法
def destroy
if !request.xhr?
render_404
return
end
if user_signed_in?
if Post.exists?(:post_id => params[:id])
if Post.post_is_mine(params[:id], current_user.id)
@return = { :error => false, :response => "Post deleted" }
else
@return = { :error => true, :response => 'You are not allowed to perform this action.' }
end
else
@return = { :error => true, :response => 'This post doesn\'t exist.' }
end
else
@return = { :error => true, :response => 'Please login before you delete a post.' }
end
render :json => ActiveSupport::JSON.encode( @return )
end
post.rb
def self.post_is_mine(post_id, user_id)
#where(:user_id => user_id, :post_id => bucket_id)
where("user_id = ? and post_id = ?", user_id, bucket_id)
end
当我在销毁帖子时检查正在运行的查询时,我只能看到.exists?
要运行的查询,但不能看到它返回 TRUE 时.post_is_mine
简单通过的查询
我尝试了其他几个名称作为方法,因为某些东西可能会导致问题,甚至只是尝试使用.post_is_mine的 if 语句,但仍然没有运行查询
关于我如何使用 where 子句的模型是否存在问题?