Skip to content

Loading…

Validations for Partial Objects #33

Closed
ssendev opened this Issue · 0 comments

2 participants

@ssendev

With sexy validations in Rails less redundant validations are possible.

validates :foo, :presence_on_step_or_active => {:step => :first}
def active?
    ...
end

# populate with current step in controller
attr_accessor :wicked_step 
class PresenceOnStepOrActiveValidator < ActiveModel::Validator
  def validate(record)
    if options[:step] == record.wicked_step || record.active?
      record.errors.add_on_blank(options[:attributes])
    end
  end
end

wicked_step could possibly be put in a more accessible place and be set in the setup_wizard before filter.

@schneems schneems closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.