-
Notifications
You must be signed in to change notification settings - Fork 14
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
Adapt errors for active admin #44
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module YAAF | ||
module ActiveAdmin | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
after_validation :sanitize_errors | ||
|
||
delegate_missing_to :main_model | ||
|
||
def self.reflect_on_association(*args) | ||
main_model_class.reflect_on_association(*args) | ||
end | ||
|
||
private | ||
|
||
def sanitize_errors | ||
form_attributes_validations = self.class.validators.map(&:attributes).flatten | ||
form_attributes_validations.each do |form_attributes_validation| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question, imagine I have the model There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes @santib, you're right about this. We should figure out another way to only move to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andresg4 that will solve the model error to be displayed in the correct field, but the form validation shouldn't be moved either if it has a specific field where to be displayed. My thinking is that if an error is set in an attribute that will be displayed in the page we don't do anything, if it doesn't have a place in the page we move it to the base. The question is how can we know that 🤔 |
||
message = errors.messages[form_attributes_validation] | ||
errors.add(:base, message) if message.present? | ||
end | ||
end | ||
|
||
def main_model | ||
models.first | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.