editing ActiveRecord collection with related drop-downs using related_select_forms
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]"
<%= 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
.
use multiple instances of FCK Editor when editing a Rails collection
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) %>
<%= fckeditor_textarea("product[]", 'description', ... %>
gave me the error:
(eval):1:in `[]': wrong number of arguments (0 for 1)
<textarea id='product_3893_description_editor'
name='product[3893][description]'>blank</textarea>
<%= fckeditor_textarea_multi( "product", "description",
@product.id, { ...}) %>
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] ...
multiple cygwin terminals without running X
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?
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.