Tag: cancan

如何显示未经授权的可以访问的错误

我正在使用Bootstrap,它有div class=”alert notice” ,它有一堆用于各种通知消息的类。 我还有一个用于评论的AJAX销毁操作,我已经添加了cancan授权。 当我尝试删除一条注释时, current_user无权访问它不起作用 – 这是正确的。 但我想要发生的是弹出一个错误信息,在Bootstrap style’d div中持续5-10秒然后消失。 这是我的CommentsController.rb上的destroy动作 def destroy respond_to do |format| if @comment.destroy format.html { redirect_to root_url, notice: ‘Comment was successfully deleted.’ } format.json { head :no_content } format.js { render :layout => false } else format.json { render json: @comment.errors, status: :unprocessable_entity } end end end 我在同一个控制器中的私有方法中设置了@comment […]