views:

23

answers:

1

Hi! I have the following Observer:

class NewsFeedObserver < ActiveRecord::Observer
  observe :photo, :comment

  def after_create(record)
  end
end

What'd I'd like to learn how to do is add a SWITCH/IF statement in the after_create, so I know which model was created

Something like:

after_create(record)
switch model_type
case "photo"
 do some stuff
case "comment"
 do some other stuff
end

Or easier to visualize:

if record == 'Photo'

How can I take record, and determine the model name?

+1  A: 

You need to setup separate observers for separate models

So for User => UserObserver , Photo => PhotoObserver

You need to tell the rails app what observers to use, that you specify in config/environment.rb

Atleast this is the standard way. For more details

http://guides.rubyonrails.org/active_record_validations_callbacks.html#observers

Rishav Rastogi
This actually worked... "record.class.name" it would be nice to find a way to also get the action... CREATE, UDPATE, etc...
AnApprentice