How can I request a library in your Rails directory from the console?

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

+3
source share
4 answers
require "#{RAILS_ROOT}/lib/query"
+2
source

For Rails 3+, use load "#{Rails.root}/lib/your_lib_file.rb" load works like require, but allows you to reload files as you edit them (unlike require, which you cannot run again). See fooobar.com/questions/98809 / ...

+4
source
>> $:.unshift 'lib'
>> require 'query'
+1

Rails 4 +:

require "#{Rails.root}/lib/query"
+1

Source: https://habr.com/ru/post/1783732/


All Articles