Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:55:34+00:00 2026-06-12T07:55:34+00:00

I am trying to build rails HTML emails, but the structure (header and footer)

  • 0

I am trying to build rails HTML emails, but the structure (header and footer) of the emails is duplicated in each one. Typically it’s not a problem, but with the inline styles as well, it seems like it can be an issue if I want to change the color. How can I pull these elements out of each file and into one?

Also, is there anyway to eliminate the duplication of text between the html.erb and text.erb files.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:55:35+00:00Added an answer on June 12, 2026 at 7:55 am

    A simple way to do it is to reference a couple of partials. Let’s say they’re named something like this:

    • _email_header.html.erb
    • _email_footer.html.erb

    Then you can refer to them inside each of your emails:

    <%= render :partial => 'email_header' %>
    Blah, email-specific content here...
    <%= render :partial => 'email_footer' %>
    

    That will work, but will still lead to a bunch of copy-paste, albeit less than the original version with the full structure inlined. A cleaner way to manage this is to set up a custom layout for these emails.

    The “Layout and Rendering” Rails Guide and the layouts section of the “Action Mailer” Rails Guide are helpful backgrounders for this, if you haven’t done this before.

    You will see from those references that there are multiple ways to invoke a layout within Action Mailer (and more ways still, outside of a mail context), but to take one example usage, you can create a layout template file here: app/views/layouts/{your_mailer_name}.html.erb. E.g., “user_mailer.html.erb”

    Its contents could look something like this:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>My Fancy Email</title>
      </head>
      <body>
        <%= render :partial => 'email_header' %>
        <%= yield %>
        <%= render :partial => 'email_footer' %>
      </body>
    </html>
    

    Note the yield call, that’s where your specific email content will render.

    This approach keeps your content “DRY“.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build my Ruby on Rails project from github on Travis-CI, but
I am trying to build a one page application and having trouble with Rails
I am trying to build a rails 3 back-end for a mobile application. However,
I'm new to ruby/rails and trying to build a simple Projects / Tags app
I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I'm trying build a method which returns the shortest path from one node to
I'm trying build a MVC framework, but I'm confused about manage themes. Well... I
Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
I'm trying to build a simple product backlog application to teach myself Rails. For
I am having a problem with rails: i'm trying to do an app for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.