Posted on 30th October 2009No Responses
Rails: Integrate FCKEditor with ActiveScaffold

When trying to use tiny_mce with I noticed that it is simply impossible due to some JS issues. So I decided to revert back to and came across gramos’ easy for and AS (get it here).

Good news is, you just need to install it, call rake :install and do some simple steps to get it running:

1.) Add a form field override to your model (let’s say our model’s name is news and we want to equip the newstext field with an editor):

def newstext_form_column(record, input_name)
  fckeditor_textarea( :record, :newstext, :name=> input_name, :width => FCKWIDTH, :height => FCKHEIGHT, :toolbarSet => FCKTOOLBAR )
end

def newstext_column(record)
  sanitize(record.newstext)
end

Notice that I added the constants FCKWITH, FCKHEIGHT and FCKTOOLBAR to my config/environment.rb to make sure we can easily edit the attributes of our editor and switch toolbars without editing 1.000 files ;)

2.) Copy over _create_form.html.erb and _update_form.html.erb to your app/views/posts/

3.) edit them by adding the following instead of the submit button tag (bottom of the file):

<input type="submit" value="Create" class="submit" onClick="var oEditor = FCKeditorAPI.GetInstance('record_<%=@record.id%>_<%='newstext'%>_editor'); document.getElementById('record_<%=@record.id%>_<%='newstext'%>_editor').value = oEditor.GetXHTML();" />

Now just replace Create with Update in the _update_form.html.erb and restart your server – here we go ;)

Share this on:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • email
  • MisterWong
  • MySpace
  • Reddit
  • RSS
  • Yahoo! Bookmarks

Related posts

Comments
Leave a Response
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img src="">