Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Access gems from Vendor folder
4 Posts
Access gems from Vendor folder

I have an executable program in my application root and that needs to access couple of gems from vendor/gems folder in my app. The reason I need to have these gems in there is I cannot install new gems on my server and I need to have them in vendor folder.

Can someone please let me know how can I point to that folder and not to a file in that folder. Thank you.

You can stick this in environment.rb (or in a configuration initializer), and then you can just do require 'nameofgem' as usual. Note that this assumes that your executable loads the Rails environment.

# This loads gems from vendor/gems/
# (see http://errtheblog.com/posts/50-vendor-everything):
config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do |dir|
  File.directory?(lib = "#{dir}/lib") ? lib : dir
end

If you run this program from command line, try passing the "-I" option:

ruby -I vendor/gems/a:vendor/gems/b foo.rb

Hi everyone, Thank you all.

Jordi, thank you so much. Your suggestion worked. I am really grateful to you all.

4 Posts
Login to add your message