I’ve got a simple active record validation on an object using this within a form:
form.error_messages({:message => '', :header_message => ''})
This in turn outputs something like “FieldName My Custom message”
What i need to do is remove the field name from the error message but leave my custom message.
Can anyone point me in the right direction for this.
One way to have complete control over the messages is to use a custom
validateblock in the model. e.g. to check that a field is not blank it would be like this:add_to_baseis intended for adding messages that aren’t related to a particular individual field (e.g. if a combination of multiple fields is illegal). This means that the CSS to highlight your invalid field won’t get added. You can work arround this by also adding a nil message to the errors for your field e.g.Alternatively, check out custom-err-message plugin – this plugin gives you the option to not have your custom validation error message prefixed with the attribute name.
Update:
add_to_baseis deprecated since Rails 3. The following can be used instead:model_instance.errors.add(:base, "Msg")Ref: https://apidock.com/rails/ActiveRecord/Errors/add_to_base