3

I have a script called query.rb in my lib directory. I want to require it so I can run it from the Rails console. I wonder if this is possible. The script work fine from within the application, so I know it's well formed and functional.

picardo
  • 24,530
  • 33
  • 104
  • 151

4 Answers4

4

For Rails 3+, use load "#{Rails.root}/lib/your_lib_file.rb" load works like require, but allows you to re-load files as you edit them (unlike require, which you cant run again). See https://stackoverflow.com/a/6361502/513739

Community
  • 1
  • 1
Excalibur
  • 3,258
  • 2
  • 24
  • 32
2

For Rails 4+:

require "#{Rails.root}/lib/query"
Andreas Profous
  • 1,384
  • 13
  • 10
2
require "#{RAILS_ROOT}/lib/query"
cam
  • 14,192
  • 1
  • 44
  • 29
1
>> $:.unshift 'lib'
>> require 'query'
cldwalker
  • 6,155
  • 2
  • 27
  • 19