Validations for Partial Objects #33

Closed
ssendev opened this Issue Aug 27, 2012 · 0 comments

Comments

Projects
None yet
2 participants
@ssendev

ssendev commented Aug 27, 2012

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 Oct 18, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment