Forum: Ruby on Rails Error handling

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.
012fbe8566eabe88e1675d77286f0543?d=identicon&s=25 Walter Horstman (Guest)
on 2006-02-14 15:13
(Received via mailing list)
Hi,

I'm stuck right now with a problem concerning error handling. I'll try
to
explain the problem in short:

In a controller class I have a method edit:

def edit
    @some_class = SomeClass.find(params[:id])
end

The record originates from a database table. What happens if the user
enters
a field that fails validation and I return to my edit page? I get the
idea
that th original value from the database gets reloaded all the time, but
I
want to see the value the user entered.

I try to create my own list of validation errors by looping through the
errors-object of the model, but I get the impression this one's also
reset
by the find-statement of my mini-example.

Hopefully somebody understands what I mean and can help me out.

Thanks in advance,
Walter
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2006-02-14 20:52
(Received via mailing list)
Walter Horstman wrote:

> enters a field that fails validation and I return to my edit page? I get
> the idea that th original value from the database gets reloaded all the
> time, but I want to see the value the user entered.
>
> I try to create my own list of validation errors by looping through the
> errors-object of the model, but I get the impression this one's also
> reset by the find-statement of my mini-example.

def edit
   @some_class = SomeClass.find( params[:id] )
   if request.post? && @some_class.update_attributes(
params[:some_class] )
     redirect_to :action => 'edit_successful'
   end
end

--
We develop, watch us RoR, in numbers too big to ignore.
This topic is locked and can not be replied to.