32423hjh32423 32423hjh32423 - 1 year ago 83
Ruby Question

How do I validate certain fields with rails devise on registration only

I have a set of custom fields attached to a devise model called Entrant.

I have two forms, one for registration form (three fields) and one which sits in the account area (12 fields). Most of the custom fields area required but only within the form the sits in the account area.

How do I achieve this?

I am using rails 4.2 and ruby 2.1

Answer Source

You can simply specify validations on actions, that is:

validates :name, presence: true, on: :create # which won't validate presence of name on update action

If you ask where to put your custom fields, then generate devise's views and update corresponding ones with these fields.