也许我只是没有使用正确的Ruby术语(如果我是的话,请纠正我),但谷歌在这方面没有帮助我.

我有一个类(称为OrderController),它扩展了另一个类(称为BaseStoreController).在BaseStoreController中,我定义了一个before_filter,它在我的整个站点中使用,除了我的OrderController之外,其余的都是小的.在这种非常特殊的情况下,我需要定义一个定制的before_filter,它需要执行一些额外的逻辑,然后调用BaseStoreController中定义的before_filter.

我不知道该怎么做.

以下是我try 过的,但"super"关键字似乎不是我所期望的:

class BaseStoreController < ActionController::Base
    before_filter :authorize

    protected
        def authorize
            #common authroization logic here
        end
 end

class OrderController < BaseStoreController
    before_filter :authorize

    protected
        def authorize
            #additional authroization logic here
            super.authorize
        end
 end

我的代码的最终结果是OrderController中的authorize方法失败,出现以下错误:

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.authorize

推荐答案

你试过用"super"而不是"super.authorize"来调用基类的"authorize"方法吗?

Ruby-on-rails相关问答推荐

安装特定版本的Ruby时出现问题(OpenSSL问题)

为什么这个rails Collection_select不呈现关联属性?

在URL中将下划线更改为连字符Ruby on Rails

在Ruby中按特定值合并时,将两个对象数组添加到一起

为什么没有生成命名空间路由?

Grape api (rails) - 未初始化常量 Endpoints::TodoAPI (NameError)

带有块捕获的 FormBuilder 辅助方法在 ERB 中不起作用

如何获取 Ruby on Rails 生成的表单元素 id 以供 JavaScript 参考?

如何在我的 rails 应用程序中测试 ActiveRecord::RecordNotFound?

对于 Visual Studio 用户来说,最好的 Ruby on Rails 环境是什么?

Rails:删除级联与依赖销毁

RSpec > 有没有办法用一个命令运行所有测试?

bundle和gem安装的区别?

如何覆盖:在 has_many 中定义的顺序

将 Rails 服务器绑定到 0.0.0.0 能给你带来什么?

rake 任务中的 def 块

RoR select_tag 默认值和选项

何时在 Ruby on Rails 中使用 lambda?

Ruby/Rails CSV 解析,UTF-8 中的无效字节序列

简单的 rails rake 任务拒绝运行并出现错误不知道如何构建任务,为什么?