Search code examples
ruby-on-railsmobileactionmailerruby-on-rails-2

Adding custom META tag to ActionMailer email in Rails 2.3.8?


I'm sending an email using an ActionMailer class in Rails 2.3.8. I need to add a META tag to the HEAD of the email. Specifically, I want to add this (ultimately for handling special CSS3 on mobile devices):

<meta name="viewport" content="width=device-width" />

I can't find a way to add this to the HEAD section of the email. Do I need to create a custom email layout that I use? If so, how do I do that? It seems like there should be an easier way than creating a custom layout.


Solution

  • It sounds like you want to send a HTML email and set the meta tag in the view. Try updating your ActionMailer content-type with something like:

    class Notifier < ActionMailer::Base
      default 'content-type' => 'text/html'
    end
    

    Then add the following line to your view's layout or <head> section:

    <meta name="viewport" content="width=device-width" />