I am trying to generate a quick registration form to use Facebook, Twitter and Linked sign in on my app. But I do have user model that validates some fields on the previous sign up procedure.
I am trying to extend the Registration controller, based on Devise, in order to use the same database for quick registration from the external sign in. This question is formulated because I am running a trial and then I have the sign up form asking for the credit card.
I have this controller:
class Users::QuickRegistrationController < Users::RegistrationsController
self.model_class = Users::RegistrationsController
end
And then I have this user model:
class User < ActiveRecord::Base
validates :name, :presence => true
validates :first_surname, :presence => true
validates :prefered_language, :presence => true
validates :dni, :presence => true, :uniqueness => true #, :format => {:with => /(^\d{7,8}[a-zA-Z]$)|(^[a-zA-Z]\d{7}[a-zA-Z]$)/, :unless => "dni.blank?"}
validates :phone_number, :presence => true, :format => { :with => /^((\d{9})|([+]\d{11}))$/, :unless => "phone_number.blank?"}, :uniqueness => true
validates :birthdate, :presence => true, :age => {:adult => :over}
validates :legal_conditions, :acceptance => {:accept => true}
validates :email, :confirmation => true
validates :email_confirmation, :presence => true
validates :password_confirmation, :presence => true, :if => "new_record?"
validates :country, :presence => true
Can I say something like validates :first_surname, :presence => false for the Users::QuickRegistrationController and :first_surname, :presence => true for Users::RegistrationsController?
Additionally, there’s a solution to solve this issue on Ruby, can you provide any tutorial or related link?
As 23tux says, validations are based on the model. What I’d do is add a new column to your model:
Then in your User model:
Then in your controller, you can ‘switch on’ the additional validations by setting
quick_registrationto false: