【问题标题】:rails before_action not in extended classesrails before_action 不在扩展类中
【发布时间】:2019-04-21 22:05:57
【问题描述】:

app/controllers/application_controller

class ApplicationController < ActionController::Base
    before_filter :set_locale_or_redirect
    before_action :set_locale

该代码在所有控制器中执行。但是,我不希望 set_locale_or_redirectset_localeapp/controllers/biblio_controller.rb 中执行我试过这个:

class Dts::BibliosController < ApplicationController
    skip_before_filter :set_locale_or_redirect, raise: false
    skip_before_action :set_locale, raise: false

没有成功。

【问题讨论】:

  • 不要使用before_filter,它已被弃用,始终使用before_action

标签: ruby-on-rails controller before-filter


【解决方案1】:

这绝对是可能的。要“跳过”控制器中的 before_action,您可以使用:

skip_before_action :action_name

在你的情况下,它会是:

skip_before_action :set_locale_or_redirect
skip_before_action :set_locale

您可以阅读更多here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多