This project is archived and is in readonly mode.

#2335 ✓duplicate
thaniyarasu

association_ids is not updated when all options are unselect

Reported by thaniyarasu | March 25th, 2009 @ 10:08 AM | in 2.x

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%>

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages