How to bypass a create record after validation wo error?

I have a specific signup process to handle, and I am turning around
the solution wo finding a clear validation …
a visitor fill in a User Registration form ( email /pwd /pwd
confirmation )

I wrote a UserValidator class to check the uniqueness of the email
field

if no user registered w this email, then no error , can proceed to

create
User.where(:email => self.email).empty? # no error

if a user is already registered w this email,

target_subdomain = Subdomain.find(self.subdomain_id)
unless target_subdomain.members.where(;email => self;email).empty?
record.errors[:email] << “is already a member” # error
else # user is not a not a member of this subdomain…
existing_user = User.where(:email => self.email).first # get
existing user record
target_subdomain.members << existing_user
# THEN I WOULD LIKE TO BYPASS THE CREATION… w no error

is there a way to do it … ? it would simplify my sign up process ,
only one form, only one process…

thanks for your feedback …

On Mon, Dec 5, 2011 at 12:30 PM, Erwin [email protected] wrote:

User.where(:email => self.email).empty? # no error

A little hard to understand what you are doing, but if you want to
save/create without validation then do:

record.save(:validate => false)

Otherwise please be a little more clear, from your code it is not
obvious.

I know about record.save(:validate => false) ( I used it in my DB
seed)

trying to be more explicit , I want to validate the record, but during
the validation process ( email uniqueness) one error type should be
considered as a specific case , then the user record should not be
created but added as a membership to a subdomain …
I guess the best way to do iy is to perform a specific email
uniqueness validation ( in a validator class), rather than user.save,
I’ll use
user.valid?
then split processing according to user.errors , in some case it’ll be
a true error ( email not unique in a subdomain) and in other case ,
email not unique in the DB but user is not yet a member of this
subdomain, so add a new membership…

the model is :
User - has_many Membership /has_many Subdomains through
Memberships
Subdomain - has_many Membership /has_many Members through
Memberships

as User are identified by emails, I can have 3 cases …
1- a brand new User ( not yet registered at all) ) =>
[email protected] -> Subdomain A
2- a User willing to register as a Member in a new Subdomain .
[email protected] -> Subdomain B ( email not unique in DB)
3- a User willing to register as [email protected] -> Subdomain A
( email not unique , already registered w Subdomain A)
case 2 and 3 will be considered as errors during email uniqueness
validation , so user.errors will not be empty …
but I can check the message , if case 2 then I can add a new
membership for the existing user…

my issue was trying to check it during validation, which seems to be
bad, better check raise the error and process it …

hope it’s a little bit enlighted ;-)) thanks for sharing your
feedback