Preventing data being written to the database on error


#1

Hello,

How do I stop data being written to the database when an error occurs?

I have this in my controller:

if @item.valid?
#stuff here
else
render :action => ‘show’, :id => @item
end

When it enters the else section, it renders the ‘show’ action, but it
adds the data to the database. How do I prevent this from happening?

Thanks


#2

On Thu, Apr 06, 2006 at 05:12:17AM +0200, Gunt wrote:

end

When it enters the else section, it renders the ‘show’ action, but it
adds the data to the database. How do I prevent this from happening?

Well, if your @item isn’t valid, it shouldn’t be successfully saved.
There’s something funny going on otherwise.

Your example doesn’t show where your save method is getting saved, or if
there’s some data manpulation – or even what your validation consists
of.
Knowing that stuff would help quite a bit.

  • Matt