mardi 30 août 2016

can't use daemons gem if installed with bundle install

I have these to .rb files inside a rails project:

require 'daemons'

Daemons.run('mqtt_subscriber.rb')


class MQTTSubscriber
  require 'mqtt'

  def run
    MQTT::Client.connect(:host => 'localhost', :port => 1883,) do |c|
      c.get('#') do |topic,message|
        puts "#{topic}: #{message}"
      end
    end
  end
end

mqtt = MQTTSubscriber.new
mqtt.run

If I run the command ruby mqtt_control.rb run it works properly when the daemons gem is installed with gem install daemons. But If the gem is installed with bundler, I get the following error:

/home/someuser/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- daemons (LoadError)
    from /home/someuser/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from mqtt_control.rb:1:in `<main>'

So it can't find the gem if it's installed though bundler. Probably because it doesn't install it in the default location.

How can I use gems installed with bundler in this way?

Aucun commentaire:

Enregistrer un commentaire