0
votes

So I installed this implementation of tinymce-rails gem:

  • Added gem 'tinymce-rails' to the Gemfile and ran bundle install
  • Configured //= require tinymce-jquery in app/assets/javascripts/application.js.
  • Messed around to get tinymce to see i am on a sub-uri (config.relative_url_root in config/application.rb)
  • Ran bundle exec rake assets:precompile for production
  • added this to my form:

    <%= f.label :body %>
    <%= f.text_area :body, :class => "mceEditor" %>

    $(function() { $('.mceEditor').tinymce({ theme: 'advanced', plugins : 'table', theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,|,bullist,numlist,outdent,indent,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect', theme_advanced_buttons2 : 'undo,redo,|,link,unlink,image,blockquote,hr,|,tablecontrols', theme_advanced_buttons3 : '', theme_advanced_toolbar_location : 'top', theme_advanced_statusbar_location : 'bottom', theme_advanced_resizing: true }); });

All works wonderfully! It's an awesome editor.

But, I don't want to liter that script code throughout my forms. Probably a dumb question. But where is the place to put this script code so it is globally (and automaticlally) going to be used on an text areas that are class "mceEditor".

Thanks!

1
So I hacked it by adding the tinymce init script to app/views/layouts/application.html.erb . But then it is included in every page, even where there is no editor.peterept
hmmm, i do not exactly how that rails thing works, but the script snippet should be placed on the page you want to have your editorThariama

1 Answers

0
votes

I followed another post to get it set up. I don't remember where I read it from..so apologies for not giving due credit to the original author. This is how i have it. I think its much cleaner and not have to sprinkle the javascript throughout.

  1. Set up a config/tinymce.yml file
  2. add <%= tinymce_assets %> <%= tinymce %> where you want it to be initialized to initialise it. For instance this is I have in a form partial


    "tinymce", :size => "100 x50" %>

This is what I have in my tinymce.yml file

theme_advanced_toolbar_location: top
theme_advanced_toolbar_align: left
theme_advanced_statusbar_location: bottom
theme_advanced_buttons1 : 
  - bold
  - italic
  - underline
theme_advanced_buttons2 : 
theme_advanced_buttons3 : 
plugins :
  - preview
  - autolink