RailsCasts Pro episodes are now free!

Learn more or hide this

tummam's Profile

GitHub User: tummam

Comments by

Avatar

I tried to decouple the receiving of a ticket from the further processing using observers.

For that I added an observer to tickets:

ruby
class TicketObserver < ActiveRecord::Observer
  def after_create(ticket)
   puts ticket.from
        end
end

This works fine when adding a new ticket through the browser. However when I send an email to my application I'll get the following exception:

E, [2013-03-19T20:19:50.352625 #8296] ERROR -- : uninitialized constant Ticket
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:230:in block in constantize'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:229:in
each'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.12/lib/active_support/inflector/methods.rb:229:in constantize'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.12/lib/active_support/core_ext/string/inflections.rb:54:in
constantize'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.12/lib/active_model/observing.rb:210:in observed_class'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.12/lib/active_model/observing.rb:203:in
observed_classes'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.12/lib/active_model/observing.rb:223:in observed_classes'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.12/lib/active_record/observer.rb:96:in
observed_classes'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.12/lib/active_model/observing.rb:219:in initialize'
/Users/tummam/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/singleton.rb:141:in
new'
/Users/tummam/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/singleton.rb:141:in block in instance'
/Users/tummam/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/singleton.rb:139:in
synchronize'
/Users/tummam/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/singleton.rb:139:in instance'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.12/lib/active_model/observing.rb:86:in
instantiate_observer'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.12/lib/active_model/observing.rb:59:in block in instantiate_observers'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.12/lib/active_model/observing.rb:59:in
each'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.12/lib/active_model/observing.rb:59:in instantiate_observers'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.12/lib/active_record/railtie.rb:117:in
block (2 levels) in class:Railtie'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:36:in instance_eval'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:36:in
execute_hook'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:43:in block in run_load_hooks'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:42:in
each'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:42:in run_load_hooks'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.12/lib/active_record/base.rb:720:in
'
/Users/tummam/Documents/Rails/ticketing/app/models/ticket.rb:1:in <top (required)>'
script/mailman_server:19:in
block (2 levels) in '
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/mailman-0.6.0/lib/mailman/router.rb:66:in instance_exec'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/mailman-0.6.0/lib/mailman/router.rb:66:in
route'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/mailman-0.6.0/lib/mailman/message_processor.rb:19:in process'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/mailman-0.6.0/lib/mailman/receiver/pop3.rb:41:in
block in get_messages'
/Users/tummam/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:665:in each'
/Users/tummam/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/pop.rb:665:in
each_mail'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/mailman-0.6.0/lib/mailman/receiver/pop3.rb:40:in get_messages'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/mailman-0.6.0/lib/mailman/application.rb:118:in
block in polling_loop'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/mailman-0.6.0/lib/mailman/application.rb:115:in loop'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/mailman-0.6.0/lib/mailman/application.rb:115:in
polling_loop'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/mailman-0.6.0/lib/mailman/application.rb:75:in run'
/Users/tummam/.rvm/gems/ruby-2.0.0-p0/gems/mailman-0.6.0/lib/mailman/application.rb:7:in
run'
script/mailman_server:16:in `'
To me it looks like the observer is the wrong idea to handle further processing. However as I envision it to be rather complex I wanted to decouple it from the receiving part of the application.

Can someone help me out with the observer problem or suggest a better method to do it?