Forum: Ruby on Rails collection_select has_and_belongs_to_many update_attributes

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Sam J. (Guest)
on 2006-04-22 00:55
(Received via mailing list)
I know there have been threads on this before but 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, Group.find(:all), :id,

In fact if I don't set the :name field like this I get an error:

undefined method `each' for #<Group:0x40ad2ee4>

which suggests that ActiveRecord is expecting to loop through this list
of groups. However with the :name field set as above the error goes
away, but the habtm relation doesn't get updated.

Actually as I was writing this I just worked out and tested the
solution, what's needed is the following:

collection_select(:user, :group_ids, Group.find(:all), :id,

Now this is something that should go in the rails recipes book!

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

I made a doc patch and submitted it:

This topic is locked and can not be replied to.