spohlenz / tinymce-rails

Integration of TinyMCE with the Rails asset pipeline
Other
816 stars 258 forks source link

using the helper method doesn't seem to work when using jQuery #51

Closed holden closed 10 years ago

holden commented 12 years ago

The helper <%= tinymce %> which generates:

<script>
//<![CDATA[
tinyMCE.init({"mode":"textareas","theme":"advanced","editor_selector":"tinymce","theme_advanced_toolbar_location":"top","theme_advanced_toolbar_align":"left","theme_advanced_statusbar_location":"bottom","theme_advanced_buttons3_add":"tablecontrols,fullscreen","plugins":"table,fullscreen","language":"en"});
//]]>
</script>

returns a 'tinyMCE is not defined' error.

It works fine when I call it directly. ie:

jQuery ->
    $('.tinymce').tinymce({
        theme_advanced_toolbar_location : 'top', 
        theme: 'simple'  
       })

I'm guessing this is a bug?

spohlenz commented 12 years ago

How are you including the TinyMCE assets (application.js or via the tinymce_assets helper)?

holden commented 12 years ago

application.js

//= require tinymce-jquery 
spohlenz commented 12 years ago

Does the following work in your application.js?

//= require tinymce

I'll have to look into what the TinyMCE libs are doing when jQuery integration is added.

nxb-dev commented 12 years ago

I tried to use both

//= require tinymce-jquery 

and

//= require tinymce

But helper method don't work.

rjhancock commented 12 years ago

In Rails 3.2, it seems the javascript include tag is placed at the bottom of the file and not at the top. The tinymce helper needs to be placed AFTER the JS gets loaded or needs to be re-written to ensure it gets loaded before calling the init method.

pawel2105 commented 12 years ago

I get undefined method tinymce in RSpec when it tests views with <%= tinymce %> in it despite it working perfectly in development. Why would this be?

spohlenz commented 12 years ago

@pawel2105 Are you adding the tinymce-rails gem to the assets group in your Gemfile, or in the global group? Make sure it is in the global group.

pawel2105 commented 12 years ago

@spohlenz I was. I hadn't restarted Spork which was causing the issue.

rtriska commented 9 years ago

Faced with the same issue. Solution: Just put '//= require tinymce-jquery' above '//= require_tree .' For example: '//= require jquery' '//= require jquery_ujs' '//= require jquery-ui' '//= require tinymce-jquery' '//= require_tree .'

In that case '<%= tinymce %>' helper works as it should.