rails user modifies email

I often thought of this, application user is actually modifying the email contents before mail gets delivered. And I just set one example of it 


# gem 'ckeditor_rails' # from https://github.com/tsechingho/ckeditor-rails
# allow modifying existing template
<textarea name="modified_email" class="ckeditor">
<%= File.read "#{Rails.root.to_s}/app/views/user_mailer/do_email.html.erb"%>
</textarea>
<%= javascript_include_tag "ckeditor-jquery" %>
<script type="text/javascript">
$('.ckeditor').ckeditor({
height: "800px",
allowedContent: true,
toolbar: [
{ name: 'document', items : [ 'Source', '-', 'Undo','Redo', '-','SpellChecker'] },
{ name: 'basicstyles', items : [ '-', 'Bold','Italic','Underline'] },
{ name: 'colors', items : [ '-', 'TextColor','BGColor' ] },
{ name: 'styles', items : [ '-', 'Styles','Format','Font','FontSize' ] },
{ name: 'tools', items : [ '-', 'Maximize' ] }
]
});
setTimeout(function(){
$("a.cke_button").attr("style", "padding:8px;");
$(".cke_chrome").attr("style", "width: 76% !important; overflow: hidden;");
}, 500);
</script>
# in your mailer
def do_email modified_contents
body = ActionView::Base.new.render :inline => CGI.unescapeHTML(modified_contents), :locals => { :token => token }
# you can have assigns as well
mail :to => recipients,
:subject => "Do Email",
:content_type => "text/html",
:body => body
end

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s