From 03b56bc0d94558ad7ff8b82e17314511a40ed16a Mon Sep 17 00:00:00 2001 From: elijah Date: Mon, 23 Jun 2014 13:52:00 -0700 Subject: Account.create - do a User.new instead of User.create, so that we can report the errors on the object if not saved. --- app/models/account.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index bee540e..67fec58 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -16,7 +16,8 @@ class Account # Returns the user record so it can be used in views. def self.create(attrs) - @user = User.create(attrs) + @user = User.new(attrs) + @user.save if @user.persisted? @identity = @user.identity @identity.user_id = @user.id @@ -28,7 +29,7 @@ class Account rescue StandardError => ex @user.errors.add(:base, ex.to_s) ensure - if @user.persisted? && (@identity.nil? || !@identity.persisted?) + if @user && @user.persisted? && (@identity.nil? || !@identity.persisted?) @user.destroy end return @user -- cgit v1.2.3