Created
April 24, 2019 12:32
-
-
Save furaji/cf44f72176b14d2f2df78193d933de56 to your computer and use it in GitHub Desktop.
ActiveRecord モデルの validates をコピー
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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