Since plugins are loaded (almost?) last you can modify (almost?) any part of the Rails core using a plugin.
Here is a silly example that changes some of the core Rails validation error messages. See active_record/validations.rb for the bland original error messages.
# ruby script/generate plugin new_errors
This creates a new directory called “new_errors” under your_app/vendor/plugins.
In the init.rb file, add the
following:
require 'new_errors'
In the lib/new_errors.rb file, add your code:
module ActiveRecord
class Errors
@@default_error_messages[:inclusion] = "is not included in the list ignoramus."
@@default_error_messages[:exclusion] = "is reserved. Pay attention!"
@@default_error_messages[:invalid] = "is invalid, moron."
@@default_error_messages[:confirmation] = "doesn't match confirmation. Pick something that does!"
@@default_error_messages[:accepted ] = "must be accepted or it will not work."
@@default_error_messages[:empty] = "can't be empty like your bank account"
@@default_error_messages[:blank] = "can't be blank like your brain."
@@default_error_messages[:too_long] = "is too long (max is %d characters). IT IS TOO LONG!!!"
@@default_error_messages[:too_short] = "is too short (min is %d characters). t.o.o.s.h.o.r.t."
@@default_error_messages[:wrong_length] = "is the wrong length (should be %d characters). I'm sorry. That is an incorrect response."
@@default_error_messages[:taken] = "has already been taken by your mom."
@@default_error_messages[:not_a_number] = "is not a number. Numbers are things like 01234 ok?"
end
end
Since plugins are loaded automatically, restart WEBrick and that is it.
HowTosPlugins – Some tutorials to get started