王筝的博客
ruby学习
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/angela/.rbenv/versions/1.9.3-p545/bin/ruby -r ./siteconf20170106-59264-robjdg.rb extconf.rb --use-system-libraries
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/angela/.rbenv/versions/1.9.3-p545/bin/ruby
    --help
    --clean
    --use-system-libraries
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-exslt-dir
    --without-exslt-dir
    --with-exslt-include
    --without-exslt-include=${exslt-dir}/include
    --with-exslt-lib
    --without-exslt-lib=${exslt-dir}/lib
    --with-libexslt-config
    --without-libexslt-config

extconf failed, exit code 1

Gem files will remain installed in /Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/extensions/x86_64-darwin-13/1.9.1-static/nokogiri-1.6.7.2/gem_make.out
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:89:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/ext_conf_builder.rb:36:in `block in build'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/tempfile.rb:320:in `open'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/ext_conf_builder.rb:19:in `build'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:161:in `block (2 levels) in build_extension'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:160:in `chdir'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:160:in `block in build_extension'
<internal:prelude>:10:in `synchronize'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:159:in `build_extension'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:198:in `block in build_extensions'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:195:in `each'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:195:in `build_extensions'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:702:in `build_extensions'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:250:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/source/rubygems.rb:90:in `block in install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/rubygems_integration.rb:130:in `preserve_paths'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/source/rubygems.rb:89:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:105:in `block in install_gem_from_spec'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/rubygems_integration.rb:162:in `with_build_args'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:104:in `install_gem_from_spec'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:262:in `block in install_sequentially'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/forwardable.rb:201:in `each'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/forwardable.rb:201:in `each'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:261:in `install_sequentially'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:91:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:15:in `install'
/Users/angela/.rbenv/rbenv.d/exec/gem-rehash/rubygems_plugin.rb:27:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/cli/install.rb:78:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/cli.rb:145:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor/command.rb:27:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor/invocation.rb:121:in `invoke_command'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor.rb:363:in `dispatch'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor/base.rb:440:in `start'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/cli.rb:9:in `start'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/bin/bundle:20:in `block in <top (required)>'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/friendly_errors.rb:5:in `with_friendly_errors'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/bin/bundle:18:in `<top (required)>'
/Users/angela/.rbenv/versions/1.9.3-p545/bin/bundle:23:in `load'
/Users/angela/.rbenv/versions/1.9.3-p545/bin/bundle:23:in `<main>'
An error occurred while installing nokogiri (1.6.7.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.7.2'` succeeds before bundling.

解决方法

brew install --force libxml2 libxslt
brew install --force libiconv

xcode-select --install

 

需要添加gem,   gem rails_config

$ EDITOR=vim bundle open devise
$ vim
$ echo $EDITOR

$ vim ~/.bashrc

加上这句 export EDITOR=vim

$ . ~/.bashrc
$ echo $EDITOR
vim
$ bundle open devise

Gem::InstallError: net-ssh requires Ruby version >= 2.0

修改Gemfile,变一下版本

 

gem 'unicorn'

group :test, :development do
  gem "rspec-rails", ">= 2.5.0"
  gem 'factory_girl', '2.6.4'
  gem 'factory_girl_rails', '1.7.0'
  gem 'faker', '1.1.2'
  gem 'forgery', '0.5.0'
  gem 'magic_encoding', '0.0.2'
  gem 'email_spec', '1.4.0'

  gem 'net-ssh', '~> 2.0'
  gem 'capistrano', '~> 2.15.7'
  gem 'capistrano-rbenv', '1.0.5'
  gem 'rb-readline','0.4.2'
end

https://github.com/activerecord-hackery/ransack

添加Gemfile

gem 'ransack'

 

view中代码

          <%= form_tag products_path, method: :get, class: "navbar-form navbar-left" do %>
            <div class="form-group">
              <%= search_field_tag("q[name_cont]", params["q"] && params["q"]["name_cont"],
                                 class:"form-control input-sm search-form", placeholder: "输入商品名称")%>
            </div>
          <% end %>

controller里

  def index
    @q = Product.ransack(params[:q])
    @products = @q.result(distinct: true)
  end 

其中 name_cont会对name字段进行模糊查询

 

http://stackoverflow.com/questions/5286117/incompatible-character-encodings-ascii-8bit-and-utf-8

http://stackoverflow.com/questions/22932282/gemloaderror-specified-mysql2-for-database-adapter-but-the-gem-is-not-loade

这个是因为在Gemfile和database.yml里写的都是mysql,

应该是mysql2.

修改之后报出新错误:“

Gem::LoadError Specified ‘mysql2′ for database adapter, but the gem is not loaded. Add `gem ‘mysql2’` to your Gemfile

配置一下mysql2 的版本

If you have this error when upgrading to rails 4.2.4 (also with rails 4.1.5) try using this version of mysql2:

gem 'mysql2', '~> 0.3.18'

https://rubygems.org/

 

今天看到了如下的提示:

Warning: You’re using Rubygems 1.8.23.2 with Spring. Upgrate to at least Rubygems 2.1.0 and run Rails 4.1.4

 

$gem update –system

update to the latest RubyGems version