Skip to content

Instantly share code, notes, and snippets.

@amolpujari
Last active December 24, 2015 23:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save amolpujari/6880037 to your computer and use it in GitHub Desktop.
Save amolpujari/6880037 to your computer and use it in GitHub Desktop.
rails user modifies email
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment