Hack to fix "undefined method" error when running rake on a gem not yet installed
Posted by Chris Blackburn
Recently, while trying to install the ultrasphinx gem for one of our projects, I ran into this little bonus:
(in /Users/cblackburn/Source/ruby/bols)
These gems that this application depends on are missing:
- ultrasphinx
Run "rake gems:install" to install them.
rake aborted!
undefined method `validates_email_address' for #<Class:0x1f577f0>
/Users/cblackburn/Source/ruby/bols/rakefile:11
(See full trace by running task with --trace)As usual I won’t bore you with why it happens other than to say the loader doesn’t work properly in this instance. To hack around it find out which models are using the ‘undefined method’ and place the following inside the class definition, before using the method.
# Hack to fix "undefined method" error when running rake on a gem not yet installed
require File.join(RAILS_ROOT, 'config', 'initializers', 'custom_validations')Comment if you need more help or if this is not clear.
