0

我只想在一行中定义我的所有观察者,现在我有这样的代码 config.active_record.observers = :user_observer, :studet_observer, :suggestion_observer, :progress_observer, :admin_observer, :employee_observer, :update_message_observer, :test_observer, :question_observer, :exam_observer, :coach_observer, :wordpress_post_observer, :answer_observer , :doubt_observer, :doubt_reply_observer, :image_format_observer #FIXME ,是否可以这样定义 config.active_record.observers_path = /app/observers

4

2 回答 2

0

只需config.autoload_paths += [#{config.root}/app/observers]在 config/application.rb 中执行

于 2013-07-21T13:24:41.503 回答
0

我使用 Dir,文件功能,它正在工作

config.active_record.observers = Dir["#{Rails.root}/app/observers/*.rb"].map{|file| File.basename(file, '.rb').to_sym}
于 2013-07-23T04:51:09.513 回答