# Additional attributes for objects in multi-object forms

**URL:** <https://www.ruby-forum.com/t/additional-attributes-for-objects-in-multi-object-forms/182158>\
**Category:** Rails\
**Created:** [January 23, 2010, 4:51pm UTC](https://www.ruby-forum.com/t/additional-attributes-for-objects-in-multi-object-forms/182158 "2010-01-23T16:51:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuramonni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@kuramonni](https://www.ruby-forum.com/u/kuramonni)\
**Post date:** [January 23, 2010, 4:51pm UTC](https://www.ruby-forum.com/t/additional-attributes-for-objects-in-multi-object-forms/182158/1 "2010-01-23T16:51:47Z")

</div>

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?
