<?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: Tag rails</title>
    <link>http://entangledbank.co.uk/articles/tag/rails?tag=rails</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>may contain traces of knowledge</description>
    <item>
      <title>editing ActiveRecord collection with related drop-downs using related_select_forms</title>
      <description>&lt;p&gt;Another problem setting the &lt;span class="caps"&gt;HTML&lt;/span&gt; &lt;code&gt;name&lt;/code&gt; attribute when editing a collection of ActiveRecord objects in a Rails application. This time I was using the &lt;code&gt;related_select_forms&lt;/code&gt; plugin to build related drop-down (select) lists. The plugin which creates all the necessary javascript to dynamically reload the second list according to the selection in the first list is kindly provided by Dimitrij Denissenko and available &lt;a href="http://dvisionfactory.googlecode.com/svn/rails/plugins/related_select_forms/"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;After a bit of research I found that the &lt;code&gt;name&lt;/code&gt; argument can be arbitrarily defined in the &lt;code&gt;html_options&lt;/code&gt; hash passed as the final argument to the select list helper (see the docs &lt;a href="http://www.railshelp.com/ActionView::Helpers::FormOptionsHelper"&gt;here&lt;/a&gt;).&lt;/p&gt;


	&lt;p&gt;First I had to build up the &lt;code&gt;name&lt;/code&gt; strings for the html in the format: &lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;product[1424][field_name]&lt;/code&gt;&lt;/pre&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;theme_name = &amp;quot;product[&amp;quot; + @product.id.to_s + &amp;quot;][theme_id]&amp;quot; 
sub_theme_name = &amp;quot;product[&amp;quot; + @product.id.to_s + &amp;quot;][sub_theme_id]&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;strong&gt;first select list&lt;/strong&gt;
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;lt;%= select(:theme, :id, theme_list, {},
            { :name =&amp;gt; theme_name } ) %&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;&lt;strong&gt;second select list&lt;/strong&gt;
 &lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;                    
&amp;lt;%= related_collection_select(
       :sub_theme, :id, [:theme, :id],  SubTheme.live_list, 
       :id, :name, :theme_id, 
       {}, 
       { :name =&amp;gt; sub_theme_name } ) %&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;


	&lt;p&gt;NB: there is a slight gotcha here with the hashes. The first (empty) hash is the &lt;code&gt;options{} &lt;/code&gt;hash used only for &lt;code&gt;{:include_blank =&amp;gt; true}&lt;/code&gt;, the second hash is used to set whatever &lt;span class="caps"&gt;HTML&lt;/span&gt; attributes you need, eg: &lt;code&gt;{ :selected =&amp;gt; @product.sub_theme_id, :multiple =&amp;gt; true, :name =&amp;gt; sub_name }&lt;/code&gt;. You &lt;strong&gt;must&lt;/strong&gt; include the first hash, empty if you don&amp;#8217;t want to use &lt;code&gt;:include_blank =&amp;gt; true&lt;/code&gt;.&lt;/p&gt;</description>
      <pubDate>Tue, 11 Sep 2007 10:13:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:7fc8e690-e059-40cb-806e-d8b8caf4f2e9</guid>
      <author>Ed</author>
      <link>http://entangledbank.co.uk/articles/2007/09/11/editing-activerecord-collection-with-related_select_forms</link>
      <category>Ruby on Rails</category>
      <category>rails</category>
    </item>
    <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>
    <item>
      <title>multiple cygwin terminals without running X</title>
      <description>I found &lt;a href="http://en.poderosa.org/"&gt;Poderosa&lt;/a&gt; to be a good solution for running multiple Cygwin terminals within a tabbed window whilst doing Rails development.  &lt;p&gt;
&lt;div style="" class="lightboxplugin"&gt;&lt;a href="/files/poderosa-big.gif" rel="lightbox" title=""&gt;&lt;img src="/files/poderosa-small.gif" alt="" title=""/&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;
As Poderosa is a Windows app it was easier to set up than  the various X Window solutions suggested, such as &lt;span class="caps"&gt;MRXVT&lt;/span&gt;. 

	&lt;p&gt;You can split the screen if you like which I do when I need to keep an eye on both my development and test log files.&lt;/p&gt;</description>
      <pubDate>Thu, 01 Mar 2007 00:08:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:2a784e15-e45e-4a2d-baf3-4b314258f300</guid>
      <author>Ed</author>
      <link>http://entangledbank.co.uk/articles/2007/03/01/multiple-cygwin-terminals-without-running-x</link>
      <category>Ruby on Rails</category>
      <category>rails</category>
    </item>
    <item>
      <title>Webrick on XP: starts OK then hangs on first request?</title>
      <description>&lt;p&gt;I had this problem and found the solution:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;netsh&lt;/span&gt; &lt;span class="ident"&gt;winsock&lt;/span&gt; &lt;span class="ident"&gt;reset&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;here: &lt;a href="http://www.db75.com/new_blog/?p=249"&gt;http://www.db75.com/new_blog/?p=249&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If anyone knows how to get XP to un-confuse itself without requiring a reboot, then it would be good to know.&lt;/p&gt;</description>
      <pubDate>Tue, 30 Jan 2007 00:09:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:b29f0f04-08a0-47ff-9379-7c93ef7a0867</guid>
      <author>Ed</author>
      <link>http://entangledbank.co.uk/articles/2007/01/30/webrick-on-xp-starts-ok-then-hangs-on-first-request</link>
      <category>Ruby on Rails</category>
      <category>rails</category>
      <category>computers</category>
    </item>
  </channel>
</rss>
