Reputation: 1380
I have a one to many relationship between Admins and Users.
Admin has_many :users
Admin accepts_nested_attributes_for :users
User belongs_to :admin
I'd like the admin edit form to include a list of all users with checkboxes next to each user, so that the admin can choose which users are associated with that admin.
I know how to do this for a many to many association, but have no idea how to make it work for the 'simpler' version.
Upvotes: 2
Views: 871
Reputation: 6942
One way is created form with form_tag and for checkbox instead simple user you can use
<%= checkbox_tag "user_ids[]" %>
It will pass array of user_id and on controller side you can iterate the array of user_ids and assign to admin.
Upvotes: 2