Why do I get cannot load such file?

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

  • 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.

    链接地址: http://www.djcxy.com/p/63332.html

    上一篇: Redmine无法启动500错误

    下一篇: 为什么我无法加载这样的文件?