Configuring TinyMCE Hammer

The default configuration creates a very minimalistic TinyMCE editor. You will likely want to change this. Below are listed the configuration options you can change. Please note, these changes effect all TinyMCE editors across your site. If you want more than one style of editor you will need to initialize the editor yourself. This is discussed in the lazy loading tutorial.

  • Tinymce::Hammer.install_path - '/javascripts/tiny_mce'

    Tinymce::Hammer.install_path is assumed to be rooted in your RAILS_ROOT/public directory. Do not prefix install_path with public/

  • Tinymce::Hammer.plugins - ['paste']
  • Tinymce::Hammer.languages - ['en']
  • Tinymce::Hammer.themes - ['advanced']
  • Tinymce::Hammer.init - # see the example below for default value


The best place to place configuration for the TinyMCE Hammer plugin is config/initializers/tinymce_hammer.rb.

Tinymce::Hammer.install_path = '/javascripts/lib/tiny_mce'
Tinymce::Hammer.plugins = %w(safari table paste paste2 tabfocus)
Tinymce::Hammer.init = [
  [:paste_convert_headers_to_strong, true],
  [:paste_convert_middot_lists, true],
  [:paste_remove_spans, true],
  [:paste_remove_styles, true],
  [:paste_strip_class_attributes, true],
  [:theme, 'advanced'],
  [:theme_advanced_toolbar_align, 'left'],
  [:theme_advanced_toolbar_location, 'top'],
  [:theme_advanced_buttons1, 'undo,redo,cut,copy,paste,pastetext,|,bold,italic,strikethrough,blockquote,charmap,bullist,numlist,removeformat,|,link,unlink,image,|,cleanup,code'],
  [:theme_advanced_buttons2, ''],
  [:theme_advanced_buttons3, ''],
  [:valid_elements, "a[href|title],blockquote[cite],br,caption,cite,code,dl,dt,dd,em,i,img[src|alt|title|width|height|align],li,ol,p,pre,q[cite],small,strike,strong/b,sub,sup,u,ul"],

Import Notes About Configuring TinyMCE

  • Don't set mode.

    The tinymce_hammer plugin manages mode. To be precise it sets mode to 'specific_textareas' with editor selector set to 'tinymce'. This means when the combined javascript file is loaded, any textarea tag with a class of tinymce will get intialized.

  • Tinymce::Hammer.init is an array of arrays. Why not a hash?!? Because hashes in ruby 1.8 are not ordered and TinyMCE throws a fit if certain initialization options appear before others. The only way to avoid this is with ordered pairs (or with an ordered hash).
  • Tinymce::Hammer.install_path is the path from your RAILS_ROOT/public folder. Prefix it with a slash. It tells tinymce_hammer where to find your TinyMCE library. It also affects where script/generate tinymce_installation installs TinyMCE for you.