Saturday 15 February 2014

ruby on rails - Missing 'template' for ActionMailer, but only when running in test mode... Calling ActionMailer base class directly -



ruby on rails - Missing 'template' for ActionMailer, but only when running in test mode... Calling ActionMailer base class directly -

this bit puzzling, when running code in production or development, rails not complain not finding template, when run test mode, giving me error saying cannot find "mailer" template...

actionmailer::base.mail(:from => 'x@s.com', :to => "webmaster@az.com", :subject => 'some test', body: 'some body).deliver

i have tried playing format block, specifying { render text: 'x' } , .html , .text, no luck.

this rails 4.

thanks!

ok, found problem, since rails conventions, tries guess template path name , view name class name when "body" passed on mailer nil. i.e. when using method directly. had debug rails framework find out:

i.e. on gems/actionmailer-4.1.6/lib/action_mailer/base.rb:

this method reply problem, can see if body eval nil, goes route of guessing path names, etc:

def collect_responses(headers) #:nodoc: responses = [] if block_given? collector = actionmailer::collector.new(lookup_context) { render(action_name) } yield(collector) responses = collector.responses elsif headers[:body] responses << { body: headers.delete(:body), content_type: self.class.default[:content_type] || "text/plain" } else templates_path = headers.delete(:template_path) || self.class.mailer_name templates_name = headers.delete(:template_name) || action_name each_template(array(templates_path), templates_name) |template| self.formats = template.formats responses << { body: render(template: template), content_type: template.type.to_s } end end responses end

ruby-on-rails ruby-on-rails-4 actionmailer

No comments:

Post a Comment