Yaay! My first plugin.
Validation messages prefixed with the field name have always bothered
me and it seems like I’m not alone. This seemed like a fairly easy fix
to attempt for my first plugin so here it is:
Using this plugin you can specify exactly where in the message you’d
like to see the field name or whether it should be displayed at all.
Simply add a %s to the validation message and you’re set.
Guard the message with [ ] brackets and the field name will be
banished from your message for ever.
You may download the plugin from
Enjoy your customized messages.
From the readme:
This Plugin enables customization of validation error messages.
Default validation error messages are always prefixed with the
offending field name. This plugin allows the developer to specify
exactly where the field name should be displayed in the message or
whether it should be displayed at all.
Tested with Rails 0.14.3
- Include %s in message to specify where the field name should be
validates_presence_of :rope, :on => :create, :message => “Can’t skip %s”
results in: Can’t skip Rope
- Messages may combine %d and %s:
validates_length_of :rope, :minimum=>10, :message => “Need at least %d
feet of %s to hang yourself”
results in: Need at least 10 feet of Rope to hang yourself
- Wrap message in [ ] to avoid field name substition
validates_presence_of :joy, :on => :create, :message => “[Cheer up!]”
results in: Cheer up!
- %s may be specified more than once:
validates_presence_of :joy, :on => :create, :message => “Happy, happy,
results in: Happy, happy, Joy, Joy!
- Default behaviour is preserved:
validates_presence_of :joy, :on => :create, :message => “is required”
results in: Joy is required