You can define a virtual attribute which will be used to determine which attributes to validate at which step, then use that attribute's value on with_options
to validate the required fields at each step.
Something like following:
In your Model:
class MyModal < ActiveRecord::Base
attr_accessor :validate_step
with_options if: :validate_step_one? do |o|
o.validates :name, presence: true
o.validates :email, presence: true
o.validates :password, presence: true
end
with_options if: :validate_step_two? do |o|
...
end
private:
def validate_step_one?
self.validate_step == 'validate_first_step'
end
def validate_step_two?
self.validate_step == 'validate_second_step'
end
end
Then in your Controller:
class MyRegistrationController < ApplicationController
def show
case step
when :first_step
user.validate_step = 'validate_first_step'
when :second_step
user.validate_step = 'validate_second_step'
end
end
end
In your controller, in the action where you build the object you need to assign either validate_first_step
or validate_second_step
based on the current step in your wizard.
Note that the values and names I've used are not very descriptive/meaningful, and you'd know much better how to name them :)