[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

update_attributes not saving data

Carl Brown

3/26/2006 7:24:00 PM

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



3 Answers

Lindsay Boyd

3/26/2006 7:40:00 PM

0

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


Eric Hodel

3/27/2006 7:15:00 AM

0

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?

Ask on the Rails mailing list.

http://lists.rubyonrails.org/mailman/list...

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

http://trackmap.rob...




Carl Brown

3/27/2006 1:49:00 PM

0


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

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