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 -- Posted via http://www.ruby-forum.com/.
Matthew Palmer
2006-Apr-06 03:42 UTC
[Rails] Re: Preventing data being written to the database on error
On Thu, Apr 06, 2006 at 05:12:17AM +0200, Gunt wrote:> 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?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
Possibly Parallel Threads
- set_default_values rocket science - continuing after_initialize/after_find misfeature
- Problem preventing double click with ajax submit button
- How to rebuild database from scratch without preventing searches
- Newbie Ajaxy Question
- Why is CDR(recordingfile) not being written to the database despite being set in the dialplan?