Rails: Integrate FCKEditor with ActiveScaffold
When trying to use tiny_mce with ActiveScaffold I noticed that it is simply impossible due to some JS issues. So I decided to revert back to FCKEditor and came across gramos’ easy fckeditor plugin for rails and AS (get it here).
Good news is, you just need to install it, call rake fckeditor: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
