Update_attributes not saving data

The run logs all look good and the data seems to be pre-set but the SQL
generated has none of the changed data…

This 'doesn’t work:
id = session[:customer_id]
@customer = Customer.find( id )
@customer.updates_attributes(params[:customer])

And, this ‘does’ work:
id = session[:customer_id]
@customer = Customer.find( id )
p = params[:customer]
@customer.first_name = p[:first_name]
@customer.last_name = p[:last_name]
@customer.save

Any ideas? (And, yes, there is an IF around the update_attributes that
indicates all-is-well…)

Thanks!!

This 'doesn’t work:
id = session[:customer_id]
@customer = Customer.find( id )
@customer.updates_attributes(params[:customer])

Do you have :customer set in the Customer model as attr_accessor? I
recall having a similar problem where specifying attr_accessor for my
attribute resulted in the attribute being updated as NULL - not with the
value I expected.

Lindsay

On Mar 26, 2006, at 11:23 AM, Carl Brown wrote:

id = session[:customer_id]
@customer = Customer.find( id )
p = params[:customer]
@customer.first_name = p[:first_name]
@customer.last_name = p[:last_name]
@customer.save

Any ideas?

Ask on the Rails mailing list.

http://lists.rubyonrails.org/mailman/listinfo/rails


Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

On 2006-03-26 14:40:16 -0500, Lindsay B. [email protected]
said:

Lindsay
Oh… Wow – thanks! That would probably work, too…

I removed the attr_accessor entirely and that resolved the issue. I
apparently have no clue how these models work yet…

Thanks for the tip!

-c

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