Nevermind... figured it out... for the record, this is how I did it...
@task = Task.update @params[''task''].keys,
@params[''task''].values
@task.each do |t|
if t.errors.full_messages().to_s == ""
flash[:notice] += t.name + " updated successfully!<br
/>"
else
flash[:notice] += t.errors.full_messages().to_s + "<br
/>"
end
end
-----Original Message-----
From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On
Behalf Of Hogan, Brian
P.
Sent: Friday, November 18, 2005 10:58 AM
To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails] How do I retrieve Errors from multiple updates
Hey all,
I''m attempting to do a multiple record update and all is saving well,
but I can''t figure out how to display the errors.
Does anyone know how I can get the error messages back to the
flash[:notice] from this code? The @task variable below seems to
contain an array of some sort..... But I can''t figure out what to call
to get the error message.
if request.post?
@task = Task.update @params[''task''].keys,
@params[''task''].values
end
I would really appreciate it if someone had some code they could send me
that would show me how to display each error message (if one exists). I
can see the error messages in the below dump but I can''t figure out how
to get at them.
@task.size => 2
[
#<Task:0x34f5c78 @attributes={"status"=>"0000000000",
"created_on"=>"2005-10-10",
"started_on"=>nil, "name"=>"test",
"assigned_to"=>"1",
"project_id"=>"9", "completed_on"=>nil,
"esthours"=>"6", "published"=>"0",
"creator_id"=>"1",
"priority"=>"0",
"service_id"=>"2", "id"=>"74",
"description"=>"test",
"difficulty"=>"0",
"due_on"=>"2005-11-24"},
@errors=#<ActiveRecord::Errors:0x34f3f38
@base=#<Task:0x34f5c78 ...>, @errors={}>,
@new_record_before_save=nil>,
#<Task:0x3491670 @attributes={"status"=>"0000000000",
"created_on"=>"2005-10-10",
"started_on"=>nil, "name"=>"Test new
procedures on DBMS04", "assigned_to"=>"1",
"project_id"=>"9",
"completed_on"=>nil, "esthours"=>"5",
"published"=>"0",
"creator_id"=>"4",
"priority"=>"5",
"service_id"=>"2", "id"=>"75",
"description"=>"The new stored procs need to be tested",
"difficulty"=>"3",
"due_on"=>"2005-10-25"},
@errors=#<ActiveRecord::Errors:0x348dec0 @base=#<Task:0x3491670 ...>,
@errors={}>, @new_record_before_save=nil>
]
Help is much appreciated!
Brian Hogan
Web Development
Learning & Technology Services
Schofield 3-B
University of Wisconsin-Eau Claire
715 836 3585
hoganbp-VnAisaAFmHY@public.gmane.org
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails