Callbacks vs Observer vs "Just adding to controller action"

ebrad
Fri, 30 Nov 2007 14:06:20 -0000

I am setting up auditing for my app where views, updates, and deletes
are recorded in my Audits table to track the life cycle of an employee
record.  I''ve read how great callbacks and observers are, but there
isn''t a way to ''callback'' for simply viewing a page.
The simplest
solution just seems to be manually creating the audit in my show
action, like this:

  def show
    @employee = Employee.find(params[:id])
    Audit.create(
      :user => Goldberg.user.name,
      :time => Time.now,
      :action => ''Viewed'',
      :employee_id => @employee.id
    )
  end

This works, I''m just wondering if there is a better approach.