Forum: Ruby on Rails checkbox with has_many

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Frank K. (Guest)
on 2006-04-21 05:20
(Received via mailing list)
Hi,

How do I set up a checkbox to use a record with a has_many field?

For example, say I have a User which is an Active Record Model.  And
say it has many names.

class User < ActiveRecord::Base
  has_many :names
end

class Name < ActiveRecord::Base
  belongs_to :user
end

Say I want to update this user and I want checkboxes that give a
choice between different names.  How would I do that?

I would want to do something like this:

<%= check_box 'user', 'names.name', {}, 0, 'Joe'  %> Joe
<%= check_box 'user', 'names.name', {}, 0, 'Bob'  %> Bob
<%= check_box 'user', 'names.name', {}, 0, 'Bill'  %> Bill

Thanks,
Frank
This topic is locked and can not be replied to.