Forum: Ruby on Rails Active Record save doesn't save! (or throw an exception)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Larry W. (Guest)
on 2006-04-28 22:33
(Received via mailing list)
PLEASE help me - this is making me insane.

Can anyone suggest any reasons for this behavior?  It occured
then went away and is now back.

In Task.rb (where task is an active record subclass)

    def clear_schedule
        puts "clearing schedule for task"
        scheduled_end_date= nil                          #reset the
scheduled end date
        halt.                                                 #this
execution stop with an error.

This is the console output this produces:

clearing schedule for task - - [28/Apr/2006:13:44:01 Eastern Daylight Time] "POST
06 HTTP/1.1" 500 10736
http://localhost:3000/tasks/edit/106 -> /tasks/update/106

When I query the db, scheduled_end_date is still set to a valid date,
though in the model I set it to nil, called save and then stopped.
were no exceptions other than this:

undefined local variable or method `halt' for #<Task:0x3a23328>

I sometimes have the opposite problem in a related piece of code for
same object/column (I set it to a real value, save it, retrieve the
from the database in the very next line of code. When I check the value

Can someone tell me what the expected behavior is within a transaction
versus outside of a transaction?  The behavior seems unpredictable in
situations but I'm not sure.  I assumed that if I was inside a
that I would still see the new value.  All of this occurs within a
http request so I assumed that all the data access was on the same

Anyway, I'm stumped and resolving this is critical to my project.
help if you can.
Michael S. (Guest)
on 2006-04-28 22:40
(Received via mailing list)
You might want to use the "save!" method, instead of "save".  The former
will throw an exception if there are problems, the latter will simply
false.  You can catch the exception and look at it to see what's really
going on.
Larry W. (Guest)
on 2006-04-28 22:49
(Received via mailing list)
I just tried that - (also wrapped the call with an if )

     if (save!)
      puts "I SAVED IT with !!!!"
      puts "THE SAVE FAILED"

It outputs "I SAVED IT ...." to the console but still the db record
a real value not nil when the program stops on the next line.
Tom M. (Guest)
on 2006-04-28 22:55
(Received via mailing list)
On Apr 28, 2006, at 11:32 AM, Larry W. wrote:

> scheduled end date
>         save
>         halt.                                                 #this
> makes execution stop with an error.

change halt to


>     end

and then type:


before hitting the page. It will show an "error" that said there's
nothing to breakpoint, which is normal, because no code is in a
breakpoint yet.

When you hit the page, the browser will freeze, and the breakpointer
will come alive, and show you the Task object.

Take a look at the @errors attribute.

-- Tom M.
Larry W. (Guest)
on 2006-04-28 23:04
(Received via mailing list)
Thank you.  I tried that and got @erros={}

but I just looked In my Postgres logs and noticed that I'm getting this
error message -

Unexpected EOF on client connection.
Michael S. (Guest)
on 2006-04-28 23:07
(Received via mailing list)
OK, so it sounds like the save is happening successfully.  Do you know
it's doing?  I'd look at the log file, to see what SQL is happening.  If
there's no SQL changing the data, then the problem is with your Ruby
code (
e.g. maybe you overrode the "scheduled_end_date=" method or something.)
the SQL is being run, then check the DB- make sure the SQL is successful
(though it's not obvious why it wouldn't be.)  If the data is in the DB,
then the problem is with reading it, not with the save.

I know- these are just general suggestions, not a solution, but I hope
a start...
Larry W. (Guest)
on 2006-04-28 23:26
(Received via mailing list)
The write is not happening at all. I've got optimistic locking on and
lock-version field did not update so the problem isn't with an
setter (though I had that problem with this same code a couple months
ago. I
assumed originally that it was back.).
Larry W. (Guest)
on 2006-04-28 23:47
(Received via mailing list)
My mistake - i was looking at the wrong task record.  The record is
saved, but the scheduled_end_date field is not getting updated.   Since
task object doesn't have scheduled_end_date over-written (any more),
else could cause that?  Something weird seems to be going on in the db

Does anyone know if there are any known issues supporting the Postgres
timestamptz type?)
This topic is locked and can not be replied to.