开发者

active record helpers defined in ~/.irbrc

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

开发者_JAVA百科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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜