开发者

ActiveRecord::Observer file placement

开发者 https://www.devze.com 2023-03-13 03:06 出处:网络
Where is the best place to keep Observer files in my rails project? The following code will have an observer for both the account class and the share class right?

Where is the best place to keep Observer files in my rails project?

The following code will have an observer for both the account class and the share class right?

class AuditObserver < ActiveRecord::Observer
  observe :account
  observe :share

  def after_update(account)
    AuditTrail.new(account, "UPDAT开发者_如何转开发ED")
  end
end


According to http://api.rubyonrails.org/classes/ActiveRecord/Observer.html - observers should be placed in the app/models directory.

Also I forgot to add config.active_record.observers = :comment_observer, :signup_observer to my application.rb file - just a heads up on a gotcha.

0

精彩评论

暂无评论...
验证码 换一张
取 消