# Association trhough checkboxes

**URL:** <https://www.ruby-forum.com/t/association-trhough-checkboxes/143497>\
**Category:** Rails\
**Created:** [July 19, 2008, 11:41am UTC](https://www.ruby-forum.com/t/association-trhough-checkboxes/143497 "2008-07-19T11:41:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@Erwin](https://www.ruby-forum.com/u/Erwin)\
**Post date:** [July 19, 2008, 11:41am UTC](https://www.ruby-forum.com/t/association-trhough-checkboxes/143497/1 "2008-07-19T11:41:26Z")

</div>

I need some help to make the right solution in rails. I have this  
model in rails:

Customer – has many – Reservations  
Customer – has many – Animals  
Reservatiion – has many – Residences – has one – Animal

A customer can make a reservation for the animals he/she is owner of.  
I made a view where I show the customer with two fields for the  
reservations and the animals which belongs to the customer. I use  
checkboxes for the animals to (un)check them for the reservation.

I get everything the work, however when some of the validations fails  
I loose some information of my model. I use ryanb´s solution for  
multiple models in a view. But in my model I check if the residence  
must be made (if the checkbox is checked). I do something like this

```auto
def new_residence_attributes(=new_residence_attributes)
  loop atrributes
    residences.build(attributes) if attribute[:status] == :reserved
  end
end
```

So only the residences I build come back in my controller, so I loose  
some information when I come back in my controller (only residences  
which are reserved). The question how do I preserve the original model  
created in the controller with the values of the view.

Thanks for your help in advance.

Greets,  
Erwin
