Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validations for Partial Objects #33

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

Validations for Partial Objects #33

ssendev opened this issue Aug 27, 2012 · 0 comments

Comments

@ssendev
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants