Adding a selected checkbox to a new nested model without polluting the model

Context: I have a GoodsReturn model with many ReturnedItem. For the new view, I create a new GoodsReturn with many new ReturnedItems from a sale (and its SoldItems). Problem: I want to have a Add/Selected checkbox with which the user can pick the items he wants to return. I know I could use a 'selected' virtual attribute but I don't want to pollute my model just for this. In fact, there is something that does exactly the opposite that I want, the :_destroy: <%= i_f.check_box :_destroy %> I would like exactly the opposite, :_select.

Anybody has figured this out before?

Thanks guys, Gam

sure is simple, i will tell you what i think you are trying to say and you can confirm it, you have a list of items, and you want the user to be able to make a selection and remove them with checkboxes? is that it?

Cool, radhames brito.

I have a list of items (all are new_record? = true) that are nested into another new record. I want the user to make a selection and ADD them with checkboxes, not remove. Those without checkboxes will just be discarded and never created.

i think i saw something similar here

http://railscasts.com/episodes/196-nested-model-form-part-1

http://railscasts.com/episodes/197-nested-model-form-part-2

it has ajax and eveything

Yeah, it's quite similar, but the example uses the _destroy facility, I want the opposite... Anyway, I'm using a virtual attribute in the meantime...

oh i see, you can handle the way the hash is passed so that you can loop true the params and check for the selected one, then only save the selected ones , i did something similar. You can handle the hash by adding to the field names in the for helper. for example addin :value[whatever] associates the items and puts then in an array in the params hash