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

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

User.where(:email => # 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 => # get
existing user record
target_subdomain.members << existing_user

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 => # no error

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

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

I know about => false) ( I used it in my DB

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,
I’ll use
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
Subdomain - has_many Membership /has_many Members through

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs