2009/9/25 Dudebot <[email protected]>: > > The weird thing is that it is working now with > f.collection_select :category_id, Category.all, :id, :header instead > of f.collection_select :category_id, Category.all, :id, :header, > {}, :multiple => false > > so :multiple => false seems to be the problem. But why? Is this a > bug?
It does seem odd. If you had said :multiple => true then I would expect to see an array of ids in params, which is what you have. It is as if the :multiple has triggered the use of an array even though you have specified it as false. In fact of course using false is I believe redundant as this is the default. I could not find anything in the docs that specifies what should happen with a false setting (as opposed to no setting). Perhaps it is intended like this, nil means there will always be a single selection, true or false means it should be passed as an array (which is what caused your code not to work) and it either will actually allow multiple selections or not. There would be some logic in this for a user who wanted at run time to decide on whether multiple selections were allowed so he could use :multiple => current_option_setting and the code picking up the params would always expect an array whatever the setting of current_option_setting. Colin > > Again, many thanks, > Craig > > On Sep 25, 2:54 pm, Colin Law <[email protected]> wrote: >> 2009/9/25 Dudebot <[email protected]>: >> >> >> >> >> >> >> >> > Thanks again, Colin--in item.rb: >> >> > belongs_to :category >> >> > And in category.rb: >> >> > has_many :items >> >> > Item has a field category_id which I intended to populate with the >> > links from an item to its category. The field header in the category >> > db is where the name of the category is. >> >> > Am I setting it up wrong then to have: >> >> > <%= f.collection_select :category_id, Category.all, :id, :header, >> > {}, :multiple => false %> >> >> > in the form? It does show up as a drop down box with the names >> > populated in it. >> >> That should be fine as far as I can see, though I don't understand the >> extra [] in the html you showed. One question, you said that it is >> not saving the new category id value, are you sure that it is not >> saving it, or is it possibly just not displaying it when you come >> round next time. Have a look in the db to see. >> >> Another question, in an earlier post you showed the record being saved >> by update_attributes, what are you doing if that fails? In other >> words is the save succeeding? >> >> I am getting to the point where I don't know what is happening I am afraid. >> >> Colin > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

