gpt4 book ai didi

ruby-on-rails - 在 Rails Controller 中跳过多个过滤器

转载 作者:行者123 更新时间:2023-12-05 07:58:44 25 4
gpt4 key购买 nike

我在 Controller 中有这样的过滤器:

class ApplicationController < ActionController::Base

before_filter :set_params
before_filter :set_default_response_format
before_filter :require_key

end

在一次操作中我需要跳过三个过滤器中的两个,所以我尝试了这个:

skip_before_filter [:require_key, :set_params], only: [:special_action]

那是行不通的。它不会跳过任何东西。然后我试了这个,它也不起作用:

skip_before_filter :require_key, only: [:special_action]
skip_before_filter :set_params, only: [:special_action]

所以我的问题是:如何在 Rails Controller 中跳过多个 before 过滤器?

最佳答案

你可以这样做

before_action :first_action, :second_action, :third_action, :fourth_action, :fifth_action, :sixth_action, :seventh_action, only: [:index, :show, :create]

关于ruby-on-rails - 在 Rails Controller 中跳过多个过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23761985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com