Chris Richards
2007-Jul-12 08:37 UTC
What do u think of this cool technique?? Can you see a flaw?
I saw this somewhere and thought it looked damn nice : def new @user = User.new end def create @user = User.new(params[:user]) @user.save! self.current_user = @user redirect_back_or_default(''/'') flash[:notice] = "Thanks for signing up!" rescue ActiveRecord::RecordInvalid render :action => ''new'' end so save! returns an exception instead of false if it couldn''t happen, which is then caught with the rescue block. It gets rid of an if, else block. Can anyone see a flaw? or a reason why this might be crappy? Thanks, Chris -- 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 -~----------~----~----~----~------~----~------~--~---