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

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).
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,

sure is simple, i will tell you what i think you are trying to say and
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?

i think i saw something similar here

it has ajax and eveything

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.

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
hash by adding [] to the field names in the for helper.
for example addin :value[whatever][] associates the items and puts
in an array in the params hash

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs