Question

I'm really tired of typing my_ar_object.errors.full_messages in my console when i'm testing things...

So, I want to define this:

module ActiveRecord
  class Base
    def err
      errors.full_messages
    end
  end
end

in my ~/.irbrc so that it is exclusive to script/console.

I don't want to define it in some rails initializer since I don't believe it belongs in the rails project (this is a irb helper)

The problem is, when I do that, this happens:

/.../gems/rails-2.3.5/lib/initializer.rb:437:in `initialize_database':NoMethodError: undefined method `configurations=' for ActiveRecord::Base:Class

Any ideas how I might make this work?

Was it helpful?

Solution

Did you load ActiveRecord in your .irbrc before defining the err method? Try adding

require 'active_record'

or

require 'rubygems'
gem 'activerecord', '2.3.5' # or whatever version you use

before defining the err method.

And another hint: irb looks for an .irbrc file in the current directory and in your home dir. So you could also craft a project-specific .irbrc in your project root directory. This way, you don't have to introduce ActiveRecord to your default irb config since it is a rather hefty dependency.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top