For some reason nothing is getting stored in my groups_user table below is the info.
My Models
group.rb
class Group < ActiveRecord::Base
has_and_belongs_to_many :users
end
user.rb
class User < ActiveRecord::Base
has_and_belongs_to_many :groups
end
groups_user.rb
class GroupsUser < ActiveRecord::Base
end
The Entity Relationship Diagram
https://i.stack.imgur.com/DsMUP.png
The Form
https://i.stack.imgur.com/n2T4E.png
The view code
<% for group in @groups %>
<%= check_box_tag "user[group_ids][]", group.id, @user.groups.include?(group) %>
<%= group.description %>
<% end %>
users_controller.rb
def update
@user = User.find(params[:id])
params[:user][:group_ids] ||= []
if @user.update_attributes(params[:user]) flash[:success] = "User updated."
redirect_to @user #end
else
@title = "Edit user"
render 'edit'
end
end
it should be
groups_usersnotgroups_userand you don’t have to create model for this table