Forum: Ruby update_attributes not saving data

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0c1d113db5922f7a2804998e9fc561e5?d=identicon&s=25 Carl Brown (Guest)
on 2006-03-26 21:24
(Received via mailing list)
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!!
Ae03102311939454d2b7f1ca3139fd97?d=identicon&s=25 Lindsay Boyd (Guest)
on 2006-03-26 21:39
> 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
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-03-27 09:15
(Received via mailing list)
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 Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com
0c1d113db5922f7a2804998e9fc561e5?d=identicon&s=25 Carl Brown (Guest)
on 2006-03-27 15:53
(Received via mailing list)
On 2006-03-26 14:40:16 -0500, Lindsay Boyd <lindsay.boyd@ntlworld.com>
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 topic is locked and can not be replied to.