When I use the below validation, I get the message "Subcategory Please Answer this"
validates :subcategory, presence: { message: "Please Answer this" }
I would prefer to get just "Please Answer this"
. How can I accomplish this? I still want it to associate with the form field, just not state it in the message.
UPDATE:
A solution was offered here: Fully custom validation error message with Rails and it states:
"Validation messages can be set for a specific model+attribute, model, attribute, or globally."
- How can they be set for specific model+attribute, model, attribute, or globally.
- How do you remove the attribute in front of the error? Do you just set the localized value of the field to "", because if so, that changes more than just my error message and I do not want that.
My use case is even more complicated b/c I have a namespaced model CommonCar::RedTrunk
and not sure how that would work with locals..
# config/locales/en.yml
en:
activerecord:
attributes:
common_car/red_trunk:
subcategory: "My label"
errors:
models:
common_car/red_trunk:
attributes:
subcategory:
blank: "Please Answer this"
I don't think this this is valid. is it? Even if it is, I need the label to show "My label", not keep it blank. So the above still would show "My Label Please Answer this"
What the proposed solution seems to recommend is setting the humanized or localized name to a blank value, so that it does not show. However, these seems more like a hack than addressing removing it from the error. Am I misunderstanding this?