Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

association_ids is not updated when all options are unselect

#2335

class User < AR has_many_belongs_to :roles end

in User model Edit view

<%Role.find(:all,:select=>"id,name").each do |role|%> <%=check_box_tag name="user[role_ids][]",role.id,@user.role_ids.include?(role.id)%><%=role.name%> <%end%>

in has_many :through (or) has_and_belongs_to_many association

when editing user details if you unselect all role name(means no role assigned to that user like public user ) options then it won't update in the intermediate (or) join_table

because params[:user][:role_ids] is nil

to avoid that you can add one more hidden with zero length string value like this

<%Role.find(:all,:select=>"id,name").each do |role|%> <%=check_box_tag name="user[role_ids][]",role.id,@user.role_ids.include?(role.id)%><%=role.name%> <%end%>

Reported by thaniyarasu · March 25th, 2009 @ 10:08 AM

State: duplicate
Milestone: 2.x
Assigned to: nobody
Importance: none