Want To Use Twitter Bootstrap Code and html_safe in Rails 4 Application

142 Views Asked by At

I have a Rails 4 application which uses a PostgreSQL 9.2.x database that stores html emails. I have a text area field that contains the html5 code for the email.

<%= @mass_email_parm["email"].html_email_text.html_safe %>

In the past I have only used straight html5 code which of course works really well. However for another application I would like to use Twitter Bootstrap code in the field to nicely format a newsletter. When I created a record with Twitter Bootstrap code everything appeared in the email but the Twitter Bootstrap formatting was ignored.

Is there a similar feature similar to html_safe or a gem available that will allow me to place Twitter Bootstrap code in a database field being used in a mailer? For now since I already have my own database I would like to avoid using another service such as MailChimp.

I have searched online but I have not found anything where html_safe is used with Twitter Bootstrap code.

I will continue searching.

1

There are 1 best solutions below

1
On BEST ANSWER

It sounds like you're saying that the CSS styling from Twitter Bootstrap is being ignored. Twitter Bootstrap comes with tons of CSS. So if you produce HTML that is not also rendering along with that CSS it will not look right. So, for emails... this just isn't a good choice because you can't really include pages and pages of CSS code with each email sent. Furthermore, even if you did it wouldn't look the way it was intended to in many email clients. Pretty much no modern CSS HTML practices are a good choice for formatting emails. You've got to use simple tables for layout and mostly simple, inline styles. This is because emails are not like browsers... in fact many email clients aren't even run in a browser... some are run in the command line. So you're trying to satisfy the least common denominator when it comes to formatting HTML in emails. And that means no Twitter Bootstrap code or anything like it.