Skip navigation

Special thanks goes to Bill Garr of thinkabout.com who figured this one out. Hope he doesn’t mind I share it with the rest of the Rails community.

in /vendor/plugins/active_scaffold

* /javascripts/activescaffold.js

1. in ActiveScaffold.ActionLink.Abstract.prototype definition (~ line 220)

onComplete: function(request) {
this.loading_indicator.style.visibility = 'hidden';

init_tinyMCE();
}.bind(this)

2. in /views/_update_form.rhtml

url_options,
:before => "update_from_tinyMCE(this);",
:after => "$('#{loading_indicator_id(:action => :update, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => :update)}');",
:complete => "$('#{loading_indicator_id(:action => :update, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => :update)}');",
:failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')",
:html => {
:href => url_for(url_options),
:id => element_form_id(:action => :update),
:class => 'update',
:method => :put
} %>

3. in your application.js (or any other .js that will be loaded)

function init_tinyMCE(){
if (!tinyMCE) return;
tinyMCE.isLoaded = false;
tinyMCE.onLoad();
}

function update_from_tinyMCE(form){
if (!tinyMCE || !form) return;
tinyMCE.triggerSave();
}

4. finally, you have to override the field display of every field that gets modified by tinyMCE. All you have to do is to change the default cleanup function, h(), to sanitize(), like so:


def body_column(record)
sanitize(record.body)
end

5. Restart Rails

6 Comments

  1. Just a quick question: this will apply to all textareas?
    Or I’ll have to tell TinyMCE what kind of textareas requires rich text editor.

    thanks a lot,cs.

  2. don’t worry, I got it now, I was extending your fabulous post with some install instructions at my blog http://clair.ro/rails/2008/02/18/howto-integrate-tinymce-into-activescaffold/.

    Thanks a lot for this big help !!!

  3. sorry bugging you, when updating a record everything is fine, but hen creating a new one i’m getting several “this.getDoc() has no properties
    http://localhost:3000/javascripts/tiny_mce/tiny_mce_src.js?1203353794
    Line 2522″ errors.

    do you have the same issues or just me?
    thx.

  4. Nice!

    You have to do the same change to _create_form.rhtml, otherwise the form data isn’t saved when creating new records.

  5. Thanks latompa and csbartus for helping iron out the kinks!

  6. I’m having some trouble. I have TinyMCE working on non-activescaffold forms using the TinyMCE javascript code. To get this to work with ActiveScaffold can I use this same method with the code changes above or do I need to use the Rails TinyMCE plugin?

    The other problem might be that I’m unsure whether I’m correctly doing step 4. Could someone tell me exactly where that code should go?

    Thank you!


One Trackback/Pingback

  1. [...] This was the post which helped me out definitely. [...]

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.