Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4837 (new enhancement)

Opened 2 years ago

Last modified 1 year ago

[PATCH] how to use collection_select with multiple and habtm

Reported by: srjoseph@hawaii.edu Assigned to: David
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords: docs
Cc:

Description

I was thinking shouldn't multiple collection_select automatically update habtm relations when you update_attributes?

In order to get multiple collection_select to work I use:

collection_select(:user, :group_ids, @groups, :id, :name,{},{:multiple=>,:name=>'group[id][]'})

This will select the groups a user is a member of, but in order to get them updated when a change is made, what's needed is the following:

collection_select(:user, :group_ids, Group.find(:all), :id, :name,{},{:multiple=>,:name=>'user[group_ids][]'})

Not this is something that should go in the rails recipes book! Or somewhere in the documentation. I've created a documentation patch for form_helper.rb

It would rock even harder if the created_on stuff held for the habtm join table as well ...

Attachments

form_options_helper_doc_patch.txt (1.1 kB) - added by srjoseph@hawaii.edu on 04/21/06 20:50:54.
doc patch

Change History

04/21/06 20:50:54 changed by srjoseph@hawaii.edu

  • attachment form_options_helper_doc_patch.txt added.

doc patch

05/29/07 04:45:59 changed by josh

  • keywords set to docs.
  • summary changed from [DOC-PATCH] how to use collection_select with multiple and habtm to [PATCH] how to use collection_select with multiple and habtm.
  • component changed from ActiveRecord to ActionPack.
  • version set to edge.
  • milestone set to 1.x.