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.
Asked
Active
Viewed 5,818 times
4 Answers
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
2
require "#{RAILS_ROOT}/lib/query"

cam
- 14,192
- 1
- 44
- 29
-
It says "no such file to load." – picardo Jan 05 '11 at 22:34
-
1what does `Dir.glob("#{RAILS_ROOT}/lib/*")` say (do that in the rails console) – cam Jan 05 '11 at 23:03
-
This would work too but it's require "#{RAILS_ROOT}/lib/query.rb" – cldwalker Jan 06 '11 at 00:55