views:

16

answers:

1

Sorry for my english ...

I need set some attributes to my object, but, I don't want to save them, I will save them after.

@object.attributes = params[:object]
@object.save

is working with other attributes like name, description ... but when I send habtm_object_ids[] rails save the association at this point:

@object.attributes = params[:object]

I want to avoid this behavior, some idea?

Thaks in advice.

A: 

You can remove the habtm_object_ids[] from the params before @object.attributes = params[:object]and use it later in the way you need. In your controller, you can do something like this:

habtm_object_ids = params.delete(:habtm_object_ids)
@object.attributes = params[:object]
@object.save
@object.habtm_objects = HabtmObject.find(habtm_object_ids)

In this case, we use the habtm_object_ids variable after saving the object to reset your association.

You may also do something comparable with a :before_save callback in in your Object class.

Yannis