Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2012 18:10
Show Gist options
  • Save anonymous/4354623 to your computer and use it in GitHub Desktop.
Save anonymous/4354623 to your computer and use it in GitHub Desktop.
class AddUserParams < OpenStruct
include DataMapper::Validations
validates_with_method :has_password?
validates_with_method :proper_user_params?
def [](key)
self.send(key)
end
def sanitize!
valid?
self
end
private
def has_password?
set_default_password if self[:user][:password].blank?
end
def set_default_password
self[:user][:password] = self[:user][:password_confirmation] = Devise.friendly_token.first(6)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment