Preventing data being written to the database on error

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs