<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>This Entangled Bank: use multiple instances of FCK Editor when editing a Rails collection</title>
    <link>http://entangledbank.co.uk/articles/2007/05/09/use-multiple-instances-of-fck-editor-when-editing-a-rails-collection</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>may contain traces of knowledge</description>
    <item>
      <title>use multiple instances of FCK Editor when editing a Rails collection</title>
      <description>&lt;p&gt;Scott Rutherford has kindly packaged up a Rails helper for the &lt;span class="caps"&gt;FCK&lt;/span&gt; Editor as a plugin. You can find it &lt;a href="http://blog.caronsoftware.com/articles/category/fckeditor-plugin"&gt;here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;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.&lt;/p&gt;&lt;p&gt;I was using the syntax:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;lt;%= text_field(&amp;quot;product[]&amp;quot;, &amp;quot;name&amp;quot;, :size =&amp;gt; 60) %&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

successfully on other fields but trying:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;lt;%= fckeditor_textarea(&amp;quot;product[]&amp;quot;, 'description', ... %&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;gave me the error:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;(eval):1:in `[]': wrong number of arguments (0 for 1)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

In order to get &lt;span class="caps"&gt;HTML&lt;/span&gt; in the correct form:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;lt;textarea id='product_3893_description_editor' 
 name='product[3893][description]'&amp;gt;blank&amp;lt;/textarea&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

it was necessary to pass the product ID to Scott&amp;#8217;s helper as an additional argument:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;lt;%= fckeditor_textarea_multi( &amp;quot;product&amp;quot;,  &amp;quot;description&amp;quot;, 
@product.id, { ...}) %&amp;gt; &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

and tweak the helper in fckeditor.rb:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;fckeditor_textarea_multi&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;object&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;field&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;new_arg&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;options&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;{})&lt;/span&gt;
   &lt;span class="punct"&gt;...&lt;/span&gt; &lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="ident"&gt;snip&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;...&lt;/span&gt;  
   &lt;span class="ident"&gt;inputs&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;&amp;lt;textarea id='&lt;span class="expr"&gt;#{id}&lt;/span&gt;' &lt;span class="expr"&gt;#{cols}&lt;/span&gt; &lt;span class="expr"&gt;#{rows}&lt;/span&gt;  
   name='&lt;span class="expr"&gt;#{object}&lt;/span&gt;[&lt;span class="expr"&gt;#{new_arg}&lt;/span&gt;][&lt;span class="expr"&gt;#{field}&lt;/span&gt;]'&amp;gt;
   &lt;span class="expr"&gt;#{value}&lt;/span&gt;&amp;lt;/textarea&amp;gt;&lt;span class="escape"&gt;\n&lt;/span&gt;&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
   &lt;span class="punct"&gt;...&lt;/span&gt; &lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="ident"&gt;snip&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
      <pubDate>Wed, 09 May 2007 00:38:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:cf6795c2-b665-4aac-8ce9-921257974661</guid>
      <author>Ed</author>
      <link>http://entangledbank.co.uk/articles/2007/05/09/use-multiple-instances-of-fck-editor-when-editing-a-rails-collection</link>
      <category>rails</category>
    </item>
  </channel>
</rss>
