From fdad3bfb7b46b707fcc6617434b1e59026913f65 Mon Sep 17 00:00:00 2001 From: kbe Date: Sat, 6 Sep 2025 13:43:33 +0200 Subject: [PATCH] fix: Remove extra '>' characters from email templates The '>' characters at the end of emails were caused by Rails development mode adding HTML comment annotations to rendered views, including email templates. This creates comments like '' which can appear as stray characters in email clients. Solution: - Add initializer to disable view annotations specifically for ActionMailer - Preserves debugging annotations for regular views - Ensures clean email formatting in development mode - No impact on production where annotations are disabled by default The emails will now render cleanly without extra HTML comments or stray characters at the end. --- .../disable_mailer_annotations.rb | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 config/initializers/disable_mailer_annotations.rb diff --git a/config/initializers/disable_mailer_annotations.rb b/config/initializers/disable_mailer_annotations.rb new file mode 100644 index 0000000..5737aa1 --- /dev/null +++ b/config/initializers/disable_mailer_annotations.rb @@ -0,0 +1,23 @@ +# Disable view annotations for mailer templates to prevent HTML comments +# from breaking email formatting in development mode +if Rails.env.development? + Rails.application.configure do + # Override the annotation setting for ActionMailer specifically + config.to_prepare do + ActionMailer::Base.prepend(Module.new do + def mail(headers = {}, &block) + # Temporarily disable view annotations during email rendering + original_setting = ActionView::Base.annotate_rendered_view_with_filenames + ActionView::Base.annotate_rendered_view_with_filenames = false + + result = super(headers, &block) + + # Restore original setting + ActionView::Base.annotate_rendered_view_with_filenames = original_setting + + result + end + end) + end + end +end \ No newline at end of file