当我在用户 Controller 中调用此销毁方法时,出现以下错误。
AbstractController::DoubleRenderError (Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".):
这很奇怪,因为老实说我只回复一次电话。
这是我的行动:
def destroy
user = User.find(params[:id])
if user.has_role_for? current_client
# then we remove the role
user.has_no_roles_for! current_client
# was that the users only role?
if user.roles.count == 0
user.destroy
end
respond_with head :ok
else
respond_with({:error=>'unauthorised'}, :status => :forbidden)
end
end
有什么想法吗?
最佳答案
尝试在respond_with行后添加“并返回”:
respond_with head :ok and return
respond_with({:error=>'unauthorised'}, :status => :forbidden) and return
关于ruby-on-rails - AbstractController::DoubleRenderError 不应该的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5415487/