Hi. I solved it by being consistent ie using instance methods for both
updates instead of a class method to update the pic and an instance
method to update the user. Still looks like a bug in Rails though. Peter
def update
begin
@user = User.find(@params[''user''][''id''])
if @params[''picture''].original_filename != ""
@picture = @user.thumbnail
@picture.update_attributes(
''name'' =>
@params[''picture''].original_filename.gsub(/[^a-zA-Z0-9.]/,''_'')
,
''size'' =>
@params[''picture''].size,
''mime'' =>
@params[''picture''].content_type,
''image'' =>
@params[''picture''].read )
end
@user.update_attributes(@params[''user''])
rescue Exception => e
flash["error"] = "Error updateing user: #{e}"
render_action ''edit''
end
redirect_to :action => ''list''
end
-----Original Message-----
From: Cutting Peter
Sent: Monday, March 21, 2005 5:29 PM
To: ''rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org''
Subject: update_attributes side effect?
Hi. I am wrestling AR to get things in and out of MySQL and it seems to
be 1 step forward and 2 back. After finally getting pictures to go in
and out I discover that uncommenting the update_attributes line below
breaks the preceding picture update code (the picture does not get
updated). This looks like a bug.
Bonus question. Updated pictures don''t appear unless I RELOAD the
browser. Firefox seems to be cacheing the old page.
Thanks for any help
Peter (Win XP)
class User < ActiveRecord::Base
has_one :thumbnail, :class_name => "Picture", :foreign_key =>
"object_id", :dependent=> true
end
here is the result of the render_text below.
{"user"=>{"name"=>"fdxcdds",
"id"=>"112", "email"=>"fdxcdds"},
"action"=>"update",
"controller"=>"users", "picture"=>#}
def update
begin
@user = User.find(@params[''user''][''id''])
if @params[''picture''].original_filename != ""
Picture.update(@user.thumbnail.id,
''name'' =>
@params[''picture''].original_filename.gsub(/[^a-zA-Z0-9.]/,''_'')
,
''size'' =>
@params[''picture''].size,
''mime'' =>
@params[''picture''].content_type,
''image'' =>
@params[''picture''].read )
end
#render_text @params.inspect
#@user.update_attributes(@params[''user''])
rescue Exception => e
flash["error"] = "Error updateing user: #{e}"
render_action ''edit''
end
redirect_to :action => ''list''
end