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