控制器中的DoubleRenderError


before_action :set_blacklisted_nfts, only: %i[blacklisted_nfts]
def blacklisted_nfts
if  @blacklisted_nft.present?
redirect_to destroy and return
end
end
def destroy
success = false
message = 'Unable to delete NFT!'
if !current_user.admin?
message = 'This action require admin privileges!'
elsif @nft.destroy
success = true
message = 'NFT deleted successfully!'
end
render layout: false, locals: {
type: success ? 'success' : 'error',
message: message,
nft_id: @nft.id
}
end
private
def set_blacklisted_nfts
@blacklisted_nft = BlacklistedNft.create(contract_address: @nft.contract_address,   contract_type: @nft.contract_type, token_id: @nft.token_id, chain: @nft.chain)
end

有人能告诉我哪里有问题吗我有这个错误:

Error: 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".

如果有redirect_to destroy,它实际上正在调用destroy方法。您可能试图重定向到destroy方法,但它直接调用它。

你实际上不能重定向到除另一个";获取";操作,重定向只是用一个URI响应浏览器,浏览器只是在上面调用一个GET,你不能有POST或DELETE或任何其他http方法(又名:http动词(。

可能在这种情况下,你只想做一个@blacklisted_nft.destroy,然后是redirect_to :back, notice: "Deleted @blacklisted_nft.name"之类的。

相关内容

  • 没有找到相关文章

最新更新