To paraphrase a common saying, "open source software is only free if your time has no value." Such was the last day of work while trying to integrate ActiveScaffold and FCKeditor. The sad thing is that it really shouldn't have been this way.
For starters, people really need to update their project's documentation (see most of the README files on github). Secondly, the documentation should include a somewhat logical example. Each code snippet should meaningfully pertain to the other, related code snippets. Thirdly, the example code should actually work. Fourthly, the previous three rules go doubly if you are dealing with JavaScript.
OK, I'm finished venting. Let's get to the meat and potatoes. I'm assuming you have a model working with ActiveScaffold, which is generally pretty simple to get up and running.
The two primary resources for installing were the (a) github page for the github fckeditor plugin and the most useful, but slightly incomplete, FCK Editor Plugin in ActiveScaffold. Without further commentary, here are the steps, minus the premature balding inducing frustration.
Install the FCKeditor plugin from within your Rails application:
script/plugin install git://github.com/davividal/fckeditor.git
rake fckeditor:install
The following steps relate to a simple admin controller for an equally simple About model.
script/generate model about content:text published:boolean
rake db:migrate
mkdir app/controllers/admin
mkdir app/helpers/admin/
mkdir -p app/views/admin/about
touch app/controllers/admin/about_controller.rb
touch app/helpers/admin/about_helper.rb
touch app/views/layouts/admin.html.erb
cp vendor/plugins/active_scaffold/frontends/default/views/_create_form.html.erb app/views/admin/about/
cp vendor/plugins/active_scaffold/frontends/default/views/_update_form.html.erb app/views/admin/about/
The Admin::About controller:
class Admin::AboutController < ApplicationController
layout 'admin'
active_scaffold :about
end
The following lines need to be included in your admin layout:
<%= javascript_include_tag :defaults, "builder", "scriptaculous", "fckeditor/fckeditor" %>
<%= active_scaffold_includes %>
Here's the about helper:
module Admin::AboutHelper
def content_form_column(record, input_name)
fckeditor_textarea(:record, :content, :ajax => true, :width => '800px', :height => '200px')
end
def content_column(record)
sanitize(record.content)
end
end
In the two admin/about partials, you need to replace submit button code with the following:
<input type="submit" value="Update" class="submit"
onClick="var oEditor = FCKeditorAPI.GetInstance('record_<%=@record.id%>_<%='content'%>_editor');
$('record_<%=@record.id%>_<%='content' %>_editor_hidden').value = oEditor.GetXHTML();" />
Substitute Update for Create as appropriate. This last bit is very important, and not mentioned pretty much anywhere except Ganesh's post. You'll notice one important difference from his code though: when assigning the hidden variable you need to actually add the "_hidden" part to the id.
Hopefully this helps someone roll with FCKeditor and ActiveScaffold (or Ajax in general) without wasting their Labor Day Sunday as I did. Let me know if something doesn't work. I know that input statement needs real angle brackets, but I'm too tired to debug that display issue just this minute.
UPDATE: Since all my new projects use jQuery, I'll be switching to this jQuery.wysiwyg.