0
votes

I need to use the ffi gem to access native extensions. When I require 'ffi' in a simple ruby script, then it works fine. But when I require ffi in my Rails application, then I get: cannot load such file -- ffi Why?

gem env shows this:

RubyGems Environment:

  • RUBYGEMS VERSION: 2.2.2
  • RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-linux]
  • INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.9.1
  • RUBY EXECUTABLE: /usr/bin/ruby1.9.1
  • EXECUTABLE DIRECTORY: /usr/bin
  • SPEC CACHE DIRECTORY: /home/adminuser/.gem/specs
  • RUBYGEMS PLATFORMS:
    • ruby
    • x86_64-linux
    • GEM PATHS:
      • /usr/lib/ruby/gems/1.9.1
      • /home/adminuser/.gem/ruby/1.9.1
1
Is the gem installed in bundler?j-dexx

1 Answers

0
votes

Add this line in your Gemfile:

gem 'ffi'

Next:

$ bundle install

Now:

require 'ffi'

You need to specify which gem you are going to use in your Gemfile in order to make it available for your Rails project with bundler.

UPDATE: I'd encourage you to checkout How does bundler bundle, how bundler require gems, and this railscast.