[Rails] How to add observer to namespace model?

348 views
Skip to first unread message

Ankit Varshney

unread,
Apr 22, 2010, 4:05:43 AM4/22/10
to rubyonra...@googlegroups.com
I have a namespace as admin and in this i have class as Admin::Business.
I want to add observer to it. I tried to add a class Admin::BusinessObserver and adding the observer in environment.rb like

config.active_record.observers = [Admin::BusinessObserver]. but it does not work. Can anybody guide me to add observer to namespaced classes.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Bruno C.

unread,
Jun 17, 2013, 2:38:20 PM6/17/13
to rubyonra...@googlegroups.com
with Rails 3.1 this worked for me:

config.active_record.observers = [ :"Admin::BusinessObserver" ]

Came up from looking at how the active_record.observer list is parsed in
gems/1.8/gems/activemodel-3.1.0/lib/active_model/observing.rb line 86

Bruno



Ankit Varshney wrote in post #907087:
> I have a namespace as admin and in this i have class as Admin::Business.
> I want to add observer to it. I tried to add a class
> Admin::BusinessObserver
> and adding the observer in environment.rb like
>
> config.active_record.observers = [Admin::BusinessObserver]. but it does
> not
> work. Can anybody guide me to add observer to namespaced classes.

--
Posted via http://www.ruby-forum.com/.
Reply all
Reply to author
Forward
0 new messages