- If you need to do different things to each class you probably want different observers for each one. Anyway, if they all share the attributes needed inside the observer you don't really need those "if". - A better looking alternative to 'record.class.name=="Order"' could be: 'record.is_a?(Order)' ; a lot shorter and looks nicer. - You could also add some private/protected methods instead of placing code inside multiple "if" statements. Something like "process_orders(record) if record.is_a?(Order)"
El jueves, 19 de noviembre de 2015, 15:06:57 (UTC+1), der_tom escribió: > > hi, > > is this the right thing todo?: > > > class AuditorObserver < ActiveRecord::Observer > > observe :order, :feedback,:jobapplicant > > def after_create(record) > if record.class.name=="Order" > ............ > end > if record.class.name=="Feedback" > ............ > end > ............ > > > > thx > > > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7d052acf-6be6-4016-8f43-c0b4e072cb39%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

