1

我的 Rails 3.2 应用程序中有一个初始化程序,它在启动时包含基于配置文件的模块。它看起来像这样:

Array(Settings.site.authentications).map(&:to_sym).each do |sym|
  AuthAuth.class_eval do
    include Object.const_get(sym)
  end
end

Array(Settings.site.authorizations).map(&:to_sym).each do |sym|
  AuthAuth.class_eval do
    include Object.const_get(sym)
  end
end

# This exception is never raised when I start the server.  So the includes 
# appear to be working correctly.
raise "method not found!" unless AuthAuth.new.respond_to? :dynamically_included_method

AuthAuth在 my ApplicationControllerin a 中使用:before_filter以确保用户经过身份验证和授权。它工作得很好,并且满足了我有一种可配置的方式来设置每个站点的授权和身份验证逻辑的要求。

但是,我注意到,当我在开发模式下运行服务器时,如果我对应用程序中的任何类进行代码更改,AuthAuth则会在没有包含模块的情况下恢复为默认行为。

除了初始化文件之外,是否有合适的地方包含此代码?

这是一个相对较小的问题。每次代码更改后重新启动开发服务器很容易,但我很好奇。

4

0 回答 0