Reputation: 55
I am trying to make use of the collection_check_boxes
method.
A group
has many users
and a user can belong to multiple groups
.
user.rb
class User < ActiveRecord::Base
has_and_belongs_to_many :groups
end
group.rb
class Group < ActiveRecord::Base
has_and_belongs_to_many :users
end
groupes.controller.rb
class GroupsController < ApplicationController
def new
@group = Group.new
end
end
new.html.slim
h1 Groupes
.hsep
.container-fluid
== form_for @group, { html: { class: 'form-horizontal', remote:true, id: 'new_user' } } do |f|
.form-group
.col-sm-10
== f.collection_check_boxes :group, :user_ids, User.all, :id, :login
== f.submit
My goal is that when a new group
is created, the user can choose which users
belong to that group with a checkbox list from all the users.
The error
ActionView::Template::Error (undefined method `merge' for :login:Symbol):
13:
14: .form-group
15: .col-sm-10
16: == f.collection_check_boxes :group, :user_ids, User.all, :id, :login
17:
18: == f.submit
I most likely missed something on how to properly use collection_check_boxes
but I just can't get around fixing it myself.
Upvotes: 0
Views: 504
Reputation: 5204
Looks like you didn't pass "text_method" argument to collection_check_boxes
If you have user's column name
when add it and remove :group
because you use it with form_for
== f.collection_check_boxes :user_ids, User.all, :id, :name
Upvotes: 1