سؤال

I'm working on ROR 3 app . I have added the following observer but I dont see any output as expected in the console or log file ( i have tried in both development and production modes)

cmd : rails g observer auditor

models:

class AuditorObserver < ActiveRecord::Observer
  observe :excel_file

  def after_update(excel_file)
    excel_file.logger.info('New contact added!')
    AuditTrail.new(execl_file, "UPDATED")
    puts "*******************"
    logger.info "********************************************"
  end
end

application.rb:

config.active_record.observers = :auditor_observer

What am I missing in here? When I change the database (thru Mysql workbench/command line) I don't see any of the above lines getting executed.. neither after_update/after_save. But after_save works if I'm executing a query thru the app itself and do @excel.save

How else are we supposed to update data in DB so that we see the observer working????

هل كانت مفيدة؟

المحلول

When you bypass activerecord by modifying the database directly, you naturally bypass all of the activerecord callbacks.

So the answer is to update the data through the application, or to use database triggers instead.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top