ruby on rails - How to accomplish an update_attributes without actually saving the changes -


possible duplicate:
rails update_attributes without save?

fundamentally, want activerecord "update_attributes" while leaving activerecord changes pending. there way accomplish this? read on if wondering why want this.

i have form consisting of 3 parts: static portion (text fields independent of each other), set of selections (grows entries filled in), , section showing effects of selections upon group of dependent objects. changing selections requires round trip server determine effects , of selections affect choices future selections. selections modeled has_many association basic model. e.g. (note [] entries designate html-selects)

include [section]   exclude [subsection]   exclude [subsection] include [section]   exclude [subsection] ... 

i have set form typical nested-attributes form. when selection changed, post fields ajax such i'm getting typical params hash (e.g. params[:basemodel][associated_models_attributes][0][:field_name]). i'd unsaved activerecord partials i'm using generate parts of original page can used generate js response (i'm using js.erb file this). using basemodel.new(params[:basemodel]) gives error

"activerecord::recordnotfound (couldn't find associatedmodel id=1 basemodel id=) 

this happening (i think) because ids existing associated records (which have non-blank ids in current record) not match blank ids generated "new" call.

i kludgy , create looks activerecord (at least enough satisfy partials) have think problem common enough there's solution it.

depending on source of activerecord::persistence#update_attributes

# file activerecord/lib/active_record/persistence.rb, line 127 def update_attributes(attributes)   # following transaction covers possible database side-effects of   # attributes assignment. example, setting ids of child collection.   with_transaction_returning_status     self.attributes = attributes     save   end end 

you can assign attributes model using

model.attributes = attributes 

where attributes hash of model fields etc.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -