You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to show custom errors when the association is not present or unique.
Rails uniqueness validation adds these errors: MyAssociation has been taken / MyAssociation must exist
When I try
validates :my_association, uniqueness: {message: "This is my custom message"}
It shows
My Association has been taken. My Association This is my custom message
I am also trying to add other errors not related to validations but to finding a model related to this.
My code:
classReport < ApplicationRecordvalidates:my_association,uniqueness: truedefafter_import_error(record)ifCustomModel.find(record[:custom_attribute])self.errors.add(:base,"Custom attribute does not exist")# This does not work! The error is not addedendend
Probably a Rails-related question but I would love it if you could help in combination with Rails Admin.
Thanks!
The text was updated successfully, but these errors were encountered:
Hi. I don't have a ready made answer for you here. If you are willing to dig into the code of the gem and the rails admin gem to find out where error messages are constructed, and how to add a hook for a custom error message, please open a PR. Make sure to add a paragraph in the README on how to set up custom error messages.
I want to show custom errors when the association is not present or unique.
Rails uniqueness validation adds these errors:
MyAssociation has been taken / MyAssociation must exist
When I try
validates :my_association, uniqueness: {message: "This is my custom message"}
It shows
My Association has been taken. My Association This is my custom message
I am also trying to add other errors not related to validations but to finding a model related to this.
My code:
Probably a Rails-related question but I would love it if you could help in combination with Rails Admin.
Thanks!
The text was updated successfully, but these errors were encountered: