organizing mailers and mailer templates
January 24, 2009 written by Surendra Singhi .When working on a large Rails project, it can be a kludge having the mailers present among the views and other model files. A nice technique to clean up things is to put all the mailers and associated views in the same folder. If you don’t know about this technique then go read it first, and then come back here.
The benefit of having the ApplicationMailer is that you can define the host for the mailers, include ActionController::UrlWriter, other setup methods in a single file and have all the mailers inherit them.
The patch written for action mailer to not use layouts for text/plain email was causing problem with exception notification plugin, so I have modified it slightly so that it checks whether the file parameter passed to it responds to content_type or not.
-
def candidate_for_layout?(options)
-
(!options[:file] || !options[:file].respond_to?(:content_type) ||
-
options[:file].content_type != ‘text/plain’) &&
-
!@template.send(:_exempt_from_layout?, default_template_name)
-
end
Further to clean things up this patch can be moved to ApplicationMailer to ensure that it is only applied for all our mailers and not for other mailers which may be used elsewhere.
Tags: action mailer, folder organization, mailers
[...] The code given below here causes the exception notification plugin to stop working, get the fixed code from this post. It also contains a better technique to organize the [...]
January 24th, 2009 at 8:35 am