use multiple instances of FCK Editor when editing a Rails collection

Posted by Ed Tue, 08 May 2007 23:38:00 GMT

Scott Rutherford has kindly packaged up a Rails helper for the FCK Editor as a plugin. You can find it here.

I was stumped for a while as I wanted to use multiple instances of the editor in a form used to edit a collection of objects, but figured it out with a little help from Scott.

I was using the syntax:

<%= text_field("product[]", "name", :size => 60) %>
successfully on other fields but trying:
<%= fckeditor_textarea("product[]", 'description', ... %>

gave me the error:

(eval):1:in `[]': wrong number of arguments (0 for 1)
In order to get HTML in the correct form:
<textarea id='product_3893_description_editor' 
 name='product[3893][description]'>blank</textarea>
it was necessary to pass the product ID to Scott’s helper as an additional argument:
<%= fckeditor_textarea_multi( "product",  "description", 
@product.id, { ...}) %> 
and tweak the helper in fckeditor.rb:
def fckeditor_textarea_multi(object, field, new_arg, options = {})
   ... [snip] ...  
   inputs = "<textarea id='#{id}' #{cols} #{rows}  
   name='#{object}[#{new_arg}][#{field}]'>
   #{value}</textarea>\n"
   ... [snip] ...
Comments

Leave a response

Comments