Repository navigation
Document creating validators by combining existing ones - #41253
eliotsykes wants to merge 1 commit into
Conversation
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
|
Please keep open/fresh, I'm hoping to get some feedback 🤞 |
|
Something feels a little off about the code here. Even though I wonder if we could add a new class MoneyValidator < ActiveModel::CompositeValidator
def compose(options)
options[:attributes].each do |attr_name|
validates attr_name, numericality: { only_integer: true }
validates "#{attr_name}_currency", inclusion: { in: %w(USD CNY JPY) }
end
end
end |
|
Thanks for the feedback. Agreed the |
|
Thank you for the PR. I think we should implement the CompositeValidator and in that case it is better to already document it instead of changing the current documentation to tell how to compose validators with the current implementation. Feel free to open a PR implementing the CompositeValidator. |
Documents how to compose new validators by combining existing validators, e.g.