This Entangled Bank: use multiple instances of FCK Editor when editing a Rails collectionmay contain traces of knowledgetag:entangledbank.co.uk,2005:TypoTypo2007-05-10T01:07:15+01:00Edurn:uuid:cf6795c2-b665-4aac-8ce9-9212579746612007-05-09T00:38:00+01:002007-05-10T01:07:15+01:00use multiple instances of FCK Editor when editing a Rails collection<p>Scott Rutherford has kindly packaged up a Rails helper for the <span class="caps">FCK</span> Editor as a plugin. You can find it <a href="http://blog.caronsoftware.com/articles/category/fckeditor-plugin">here</a>.</p>
<p>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.</p><p>Scott Rutherford has kindly packaged up a Rails helper for the <span class="caps">FCK</span> Editor as a plugin. You can find it <a href="http://blog.caronsoftware.com/articles/category/fckeditor-plugin">here</a>.</p>
<p>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.</p><p>I was using the syntax:</p>
<div class="typocode"><pre><code class="typocode_default "><%= text_field("product[]", "name", :size => 60) %></code></pre></div>
successfully on other fields but trying:
<div class="typocode"><pre><code class="typocode_default "><%= fckeditor_textarea("product[]", 'description', ... %></code></pre></div>
<p>gave me the error:</p>
<div class="typocode"><pre><code class="typocode_default ">(eval):1:in `[]': wrong number of arguments (0 for 1)</code></pre></div>
In order to get <span class="caps">HTML</span> in the correct form:
<div class="typocode"><pre><code class="typocode_default "><textarea id='product_3893_description_editor'
name='product[3893][description]'>blank</textarea></code></pre></div>
it was necessary to pass the product ID to Scott’s helper as an additional argument:
<div class="typocode"><pre><code class="typocode_default "><%= fckeditor_textarea_multi( "product", "description",
@product.id, { ...}) %> </code></pre></div>
and tweak the helper in fckeditor.rb:
<div class="typocode"><pre><code class="typocode_ruby "><span class="keyword">def </span><span class="method">fckeditor_textarea_multi</span><span class="punct">(</span><span class="ident">object</span><span class="punct">,</span> <span class="ident">field</span><span class="punct">,</span> <span class="ident">new_arg</span><span class="punct">,</span> <span class="ident">options</span> <span class="punct">=</span> <span class="punct">{})</span>
<span class="punct">...</span> <span class="punct">[</span><span class="ident">snip</span><span class="punct">]</span> <span class="punct">...</span>
<span class="ident">inputs</span> <span class="punct">=</span> <span class="punct">"</span><span class="string"><textarea id='<span class="expr">#{id}</span>' <span class="expr">#{cols}</span> <span class="expr">#{rows}</span>
name='<span class="expr">#{object}</span>[<span class="expr">#{new_arg}</span>][<span class="expr">#{field}</span>]'>
<span class="expr">#{value}</span></textarea><span class="escape">\n</span></span><span class="punct">"</span>
<span class="punct">...</span> <span class="punct">[</span><span class="ident">snip</span><span class="punct">]</span> <span class="punct">...</span></code></pre></div>