我想允许匿名访问我的论坛。我正在使用 Forem Gem 和 Devise Gem。我的 ApplicationController 中有一个 before_filter 来确保用户登录。
before_filter :authenticate_user!
在我自己的 Controller 中,我使用skip_filter来允许匿名访问操作,但我不知道如何为Forem Gem中的 Controller 执行此操作。
我可以将 before_filter 语句从我的 ApplicationController 移动到我自己的每个 Controller 中,但我不愿意。
最佳答案
感谢 Ryan 的回答,只是想指出该文件应该是:
forem/application_controller_decorator.rb
否则,它将不会加载该初始化程序代码(注意:下划线 - 不是破折号)。
重申一下,初始化代码应该是:
Rails.application.config.to_prepare do
Dir.glob(Rails.root.join("app/**/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end
这样它将在开发模式下根据每个请求重新加载。
希望这能为某人节省几个小时!
关于ruby-on-rails-3.1 - 如何在 Rails Forem Gem 中的过滤器之前跳过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9284452/