Skip to content

Instantly share code, notes, and snippets.

@furaji
Created April 24, 2019 12:32
Show Gist options
  • Save furaji/cf44f72176b14d2f2df78193d933de56 to your computer and use it in GitHub Desktop.
Save furaji/cf44f72176b14d2f2df78193d933de56 to your computer and use it in GitHub Desktop.
ActiveRecord モデルの validates をコピー
class ApplicationForm
include ActiveModel::Model
include ActiveModel::Attributes
def self.copy_validations_from(model)
attribute_types.keys.each do |key|
model.validators_on(key).each do |validator|
validates(key, validator.kind => validator.options)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment