Question

I have a problem running radiant mailer extension SystemStackError in SiteController#show_page on any page, which doesn't contain mailer functionality. I've found, that that there is a module that casus issues:

Module MailerProcess
  include RecaptchaMailer

  def self.included(base)
    base.class_eval {
      alias_method_chain :process, :mailer
      attr_accessor :last_mail
    }
  end

  def process_with_mailer(request, response)
    # If configured to do so, receive and process the mailer POST
    if Radiant::Config['mailer.post_to_page?'] && ... 
       # here process_mail from RecaptchaMailer called - works fine 
    end
    process_without_mailer(request, response)
  end
end

And here process_without_mailer is what completely confuses me - there is no such definition. THis method actually causes lots of "SHOW TABLES" in logs and finally the exception. This method i suspect is some more or less Rails part, bcause there are the same calls e.g. in actionpack-2.3.18/lib/action_controller/filters.rb (process_without_filters), rails-4.0.0/guides/source/active_support_core_extensions.md (process_without_stringified_params) - those methods also don't have any definitions.

So, there are two questions:

  1. why process_with_mailer is called during any page load?
  2. what's the magic behind process_without_mailer?

UPD:

ok, commenting out method process_with_mailer gives error during startup:

/home/sab/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-2.3.18/lib/active_support/core_ext/module/aliasing.rb:34:in `alias_method': undefined method `process_with_mailer' for class `Page' (NameError)
        from /home/sab/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-2.3.18/lib/active_support/core_ext/module/aliasing.rb:34:in `alias_method_chain'
        from /home/sab/_work/radiant-cms/vendor/extensions/mailer/lib/mailer_process.rb:6:in `block in included'
        from /home/sab/_work/radiant-cms/vendor/extensions/mailer/lib/mailer_process.rb:5:in `class_eval'

So, probably alias_method_chain causes calling method every page load, but mechanics is unclear to me. I've found some ActiveSuppor doc.

UPD2 well i ended up with

  1. Reading Ruby on Rails: alias_method_chain, what exactly does it do?
  2. commenting out process_with_mailer and alias_method_chain. on that configuration it sends emails, so that's acceptable. i still would like to know, what was author's general idea.
Was it helpful?

Solution

Read the article about alias_method_chain again, until you really get it. That is indeed what triggers process_with_mailer every time process is called.

By commenting out process_with_mailer and alias_method_chain, you essentially broke this code as it will never trigger again. The reason that emails are now being sent, is because the mailer extension can be set up in two ways;

  • if Radiant::Config['mailer.post_to_page?'] is true, mailer forms will post to the current url. E.g. it will POST to domain.tld/contact, then Radiant finds the page at that path, and processes it. Thanks to the alias_method_chain, it will find out if the form has just been posted, and then do it's thing to actually send the mail.
  • if Radiant::Config['mailer.post_to_page?'] is not true (or not set), the contact form will POST to something like domain.tld/pages/:id/mail. That request is not handled by Radiant's SiteController, but by the MailController, which does not use process_with_mailer. The second is apparently your case, as you say that emails are properly sent now after commenting out the alias_method_chain.

Exactly what caused the SystemStackError is hard to say without a more complete error message, but: judging from something you pasted (activesupport-2.3.18), you are trying to use this extension with radiant 1.1.3, while it has not been updated in 4 years.. Do you actually use the recaptcha functionality? If not, I'd say drop this fork and use the 'normal' mailer extension that it is based on: https://github.com/radiant/radiant-mailer-extension

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top