editing ActiveRecord collection with related drop-downs using related_select_forms

Posted by Ed Tue, 11 Sep 2007 09:13:00 GMT

Another problem setting the HTML name attribute when editing a collection of ActiveRecord objects in a Rails application. This time I was using the related_select_forms 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 here.

After a bit of research I found that the name argument can be arbitrarily defined in the html_options hash passed as the final argument to the select list helper (see the docs here).

First I had to build up the name strings for the html in the format:

product[1424][field_name]
theme_name = "product[" + @product.id.to_s + "][theme_id]" 
sub_theme_name = "product[" + @product.id.to_s + "][sub_theme_id]"
first select list
<%= select(:theme, :id, theme_list, {},
            { :name => theme_name } ) %>

second select list

                    
<%= related_collection_select(
       :sub_theme, :id, [:theme, :id],  SubTheme.live_list, 
       :id, :name, :theme_id, 
       {}, 
       { :name => sub_theme_name } ) %>

NB: there is a slight gotcha here with the hashes. The first (empty) hash is the options{} hash used only for {:include_blank => true}, the second hash is used to set whatever HTML attributes you need, eg: { :selected => @product.sub_theme_id, :multiple => true, :name => sub_name }. You must include the first hash, empty if you don’t want to use :include_blank => true.

multiple cygwin terminals without running X

Posted by Ed Thu, 01 Mar 2007 00:08:00 GMT

I found Poderosa to be a good solution for running multiple Cygwin terminals within a tabbed window whilst doing Rails development.

As Poderosa is a Windows app it was easier to set up than the various X Window solutions suggested, such as MRXVT.

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.

Webrick on XP: starts OK then hangs on first request?

Posted by Ed Tue, 30 Jan 2007 00:09:00 GMT

I had this problem and found the solution:

netsh winsock reset

here: http://www.db75.com/new_blog/?p=249

If anyone knows how to get XP to un-confuse itself without requiring a reboot, then it would be good to know.