2

I am building a rails engine that uses the Nokogiri gem and I'm having trouble with my development setup in MacOS 10.7 and 10.8:

In order for Nokogiri to work properly in my setup, I updated the libxml and libxslt libraries with:

brew update
brew install libxslt
brew upgrade libxml2
gem uninstall nokogiri
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28

And Nokogiri works properly if I use it in a "regular" rails app (Include it in the Gemfile, run bundle install).

The problem appears when I try to use Nokogiri from a Rails Engine that I'm building and using from my app as a gem.

In gemspec:

s.add_dependency 'nokogiri' # XML parsing

I also tried the following in the top of the Gem's Gemfile:

gem 'nokogiri'

When I start an app that uses my Rails Engine gem, I get the following warning:

WARNING: Nokogiri was built against LibXML version 2.9.0, but has dynamically loaded 2.7.8

How do I configure the gem and/or bundler and/or Rails to use the correct version of Nokogiri and libxml and libxslt ?

Also, here's the output of nokogiri -v

# Nokogiri (1.5.9)
    ---
    warnings: []
    nokogiri: 1.5.9
    ruby:
      version: 1.9.3
      platform: x86_64-darwin12.3.0
      description: ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.3.0]
      engine: ruby
    libxml:
      binding: extension
      compiled: 2.9.0
      loaded: 2.9.0
4

1 回答 1

9

将 Rails Engine gem 放在应用程序 Gemfile 的顶部。然后,在 Rails 引擎的 gemspec 和 Gemfile 中,确保在使用 libxml(如 pg)的其他 gem 之前有 nokogori。

于 2013-06-05T14:50:06.123 回答