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

···

--
Posted via http://www.ruby-forum.com/\.

Ask on the Rails mailing list.

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

···

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

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?

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

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

···

On 2006-03-26 14:40:16 -0500, Lindsay Boyd <lindsay.boyd@ntlworld.com> said:

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