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 ..

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • DK at Dec 5, 2011 at 6:04 pm

    On Mon, Dec 5, 2011 at 12:30 PM, Erwin wrote:

    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
    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.

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

    thanks for your feedback ..

    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Erwin at Dec 5, 2011 at 10:27 pm
    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) ) =>
    member1@domain.com -> Subdomain A
    2- a User willing to register as a Member in a new Subdomain .
    member1@domain.com -> Subdomain B ( email not unique in DB)
    3- a User willing to register as member1@domain.com -> 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



    On Dec 5, 7:04 pm, DK wrote:
    On Mon, Dec 5, 2011 at 12:30 PM, Erwin wrote:
    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
    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.








    is there a way to do it ... ?  it would simplify my sign up process ,
    only one form, only one process...
    thanks for your feedback ..
    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 5, '11 at 5:30p
activeDec 5, '11 at 10:27p
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Erwin: 2 posts DK: 1 post

People

Translate

site design / logo © 2021 Grokbase