Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method add_observer when using Observer for Mailer from Rails Engine #46

Open
AndyObtiva opened this issue May 11, 2016 · 1 comment

Comments

@AndyObtiva
Copy link

AndyObtiva commented May 11, 2016

I keep getting this error when I start a Rails 4.2.4 application consuming a Rails Engine with a Mailer Observer configured.

Details are below with some code information replaced with placeholders to protect my client's code rights.

engine.rb configuration:

config.autoload_paths += %W(#{config.root}/app/observers)
config.active_record.observers = 'NameOfModule::NameOfObserver'

observer code:

module NameOfModule
  class NameOfObserver < ActiveRecord::Observer
    observe 'NameOfModule::NameOfMailer'
    ...

Error:

$ rails s
=> Booting Thin
=> Rails 4.2.4 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/User/.rvm/gems/ruby-2.3.0@code/gems/attr_encrypted-1.3.5/lib/attr_encrypted.rb:259:in `method_missing': undefined method `add_observer' for Buccaneer::EntryMailer:Class (NoMethodError)
    from /Users/User/.rvm/gems/ruby-2.3.0@code/gems/actionmailer-4.2.4/lib/action_mailer/base.rb:569:in `method_missing'
    from /Users/User/.rvm/gems/ruby-2.3.0@code/gems/rails-observers-0.1.2/lib/rails/observers/active_model/observing.rb:364:in `add_observer!'
    from /Users/User/.rvm/gems/ruby-2.3.0@code/gems/rails-observers-0.1.2/lib/rails/observers/activerecord/observer.rb:105:in `add_observer!'
    from /Users/User/.rvm/gems/ruby-2.3.0@code/gems/rails-observers-0.1.2/lib/rails/observers/active_model/observing.rb:341:in `block in initialize'
    from /Users/User/.rvm/gems/ruby-2.3.0@code/gems/rails-observers-0.1.2/lib/rails/observers/active_model/observing.rb:341:in `each'
    from /Users/User/.rvm/gems/ruby-2.3.0@code/gems/rails-observers-0.1.2/lib/rails/observers/active_model/observing.rb:341:in `initialize'

I will add any further details if I discover any.

@AndyObtiva
Copy link
Author

AndyObtiva commented May 11, 2016

OK, I fixed by not setting config.active_record.observers= in engine.rb nor having an observe class method call in Observer, yet instead just using register_observer class method call in Mailer itself. Must be a special issue with Rails Mailer Observers.

Still, it would be nice not to get that exception for add_observer (is that old API?) when I register via observe class method in Observer instead of using register_observer

@AndyObtiva AndyObtiva changed the title Having an issue using Observer from Rails Engine add_observer exception when using Observer for Mailer from Rails Engine May 11, 2016
@AndyObtiva AndyObtiva changed the title add_observer exception when using Observer for Mailer from Rails Engine undefined method add_observer when using Observer for Mailer from Rails Engine May 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant