Update_attributes not saving data


#1

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!!


#2

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


#3

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. - removed_email_address@domain.invalid - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com


#4

On 2006-03-26 14:40:16 -0500, Lindsay B. removed_email_address@domain.invalid
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