Additional attributes for objects in multi-object forms

Hello,

So basically I have a case of multiple objects in one form. I have
implemented sort of bulk_update_or_delete method that updates all the
fields for all of the objects and which is working fine at the moment.
However, I’m still a bit lost with the whole process when it comes to
additional parameters such as _delete.

I currently use the

<%= f.check_box :_delete %>

However the handler in the model (bulk_update_or_delete) looks like this

def self.bulk_update_or_delete(attributes)
for a in attributes do
unless a[1][’_delete’] == ‘1’
u = User.find_by_id(a[0].to_i)
a[1].delete(’_delete’)
u.attributes = a[1]
u.save(false)
else
u = User.find_by_id(a[0].to_i)
u.destroy
end
end
end

Which definitely looks a lot like a hack. Compared to some of the
examples I found, I had to manually remove the _delete attribute from
the list or I got an error when calling u.attributes = a[1]

While this semi-hack works nicely, my problem arises when my form has a
checkbox next to a password. The idea of my UI solution is that the
password for this user will only be set if and only if this checkbox is
checked. My initial solution would be to add an attribute for the object
in the form along the lines of ‘change_password’ and should it be
checked, remove the password attribute from the list of submitted
attributes along with the change_password attribute itself.

I can think of doing this in the controller before submitting it to the
bulk_update_or_delete but I’d rather do it there (it resides in the user
model). Basically I’m looking for an alternative, neater, solution for
both the original manual removal of these attributes as well as
implementing the additional checkbox.

Any advice?