Hello guys, I was wondering how good is it to use exceptions for everything in your rails application. I mean like using save! everytime instead of the plain save. Or using begin and rescue in every action in your controller. Is this adviseable? does it hit the application on the performance side? Is it better to avoid them and use them just when really necessary? I will appreciate any comments you may have on this. Thanks in advance. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Adrian De la cruz
2007-Sep-11 05:32 UTC
Re: Using exceptions on all of my controller actions
Ok, here is a little example to make things clearer: This is the ordinary form: def update @user = User.find( params[ :id ] ) if @user.update_attributes( params[ :user ] ) flash[ :notice ] = ''User was successfully updated.'' redirect_to :action => ''list'' else render :action => ''edit'' end end This is the form I prefer, but I don''t know if I''m paying an excesive price using exceptions instead of simple if''s. def update begin @user = User.find( params[ :id ] ) @old_name = @user.login @user.update_attributes!( params[ :user ] ) flash[ :notice ] = update_ok( @user.login ) redirect_to :action => ''list'' rescue ActiveRecord::RecordNotFound => e flash[ :error ] = find_error redirect_to :action => ''list'' rescue => e flash[ :error ] = update_error( @old_name ) render :action => ''edit'' end end What do you think? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---