bb2
bb2

Reputation: 2982

How to sign up with devise user and ignore some validations

I have a setup devise for user signup, this is working and so are the password validations that come by default. I have updated that devise model to include other fields like hometown, address, etc. I still want the user to be able to sign up by only providing email and password. When I added validations for fields like address, gender, etc, when a user wants to sign up, it will complain that those fields are empty. How can I ignore specific validations such as address, gender, etc, without ignoring the password validation that came by default? I saw something about using a flag inside .save(:validate => false) but I don't want to use this because it will ignore password validation.

Is there a way to solve this without having to create an additional model? User and UserAdditionalInfo? I want everything in User.

Thanks.

Upvotes: 0

Views: 126

Answers (1)

usha
usha

Reputation: 29349

when you add the validation for address, say :allow_blank => true

For eg:

validates_length_of :address, :maximum => 30, :allow_blank => true

This will allow you to create a user without checking the address length.

Upvotes: 1

Related Questions