Charlie Hubbard
2006-Aug-14 14:09 UTC
[Rails] ActionMailer in an infinite loop? Looks like framework bug.
I would rather post this on the dev list since it looks like only the developers can explain why this is failing. However, I can''t find where you subscribe to it! Any ideas? Here is my problem. Whenever I try to send an email I get a SystemStackError saying stack level too deep. Here is the exception trace: D:/dev/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.5/lib/action_mailer/helpers.rb:96:in `inherited_without_helper'' D:/dev/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.5/lib/action_mailer/helpers.rb:96:in `inherited'' #{RAILS_ROOT}/app/models/notifications.rb:1 #{RAILS_ROOT}/app/models/user.rb:52:in `send_new_password'' #{RAILS_ROOT}/app/controllers/user_controller.rb:42:in `forgot_password'' My class is the Notifications.rb class you see in the stack at line one. So this is happening when it tries to load the ruby file. So I opened helpers.rb in ActionMailer and I found the following: Line 95: helpers.rb: ActionMailer 1.2.5 --------------------------------------- def inherited_with_helper(child) inherited_without_helper(child) begin child.master_helper_module = Module.new child.master_helper_module.send :include, master_helper_module child.helper child.name.underscore rescue MissingSourceFile => e raise unless e.is_missing?("helpers/#{child.name.underscore}_helper") end end The first line of this method is inherited_without_helper, but when I searched for this method I found that it was an alias for the same method. Here is where I found that problem: Line 15: helpers.rb: ActionMailer 1.2.5 --------------------------------------- class << self alias_method :inherited_without_helper, :inherited alias_method :inherited, :inherited_with_helper end Notice it''s defining inherited_without_helper to be inherited_with_helper so a call to inherited_without_helper is the same as calling inherited_with_helper! Hence the infinite loop. So I started to just define this method in my class since it looks like it doesn''t do anything. Then I ran into another issue that looks like the same problem. Line 109: helpers.rb: ActionMailer 1.2.5 ---------------------------------------- def initialize_template_class_with_helper(assigns) returning(template = initialize_template_class_without_helper(assigns)) do template.extend self.class.master_helper_module end end Line 22: -------- alias_method :initialize_template_class_without_helper, :initialize_template_class alias_method :initialize_template_class, :initialize_template_class_with_helper This one however, I can''t find and I don''t know what it is supposed to do. Clearly it does something since it returns a template and does something with a block, but I can''t find it defined anywhere. Looking at this code I''m not sure how this would ever work. I don''t know where else to go. Please help I''m totally stuck, and I''ve already posted once on this forum, tried the rails IRC channel, and I''ve continued to debug this. I''m lost. Charlie -- Posted via http://www.ruby-forum.com/.