Search code examples
ruby-on-railsrubyruby-on-rails-4ruby-on-rails-5ruby-on-rails-6

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


Solution

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