简体   繁体   中英

Snow Leopard & Ruby on Rails - SQLite3 issue

I just upgraded to snow leopard. Before, I had everything running fine, but now when I start the server from the terminal I get:

=> Booting WEBrick
=> Rails 2.3.3 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2009-08-28 23:18:19] INFO  WEBrick 1.3.1
[2009-08-28 23:18:19] INFO  ruby 1.8.7 (2008-08-11) [universal-darwin10.0]
[2009-08-28 23:18:19] INFO  WEBrick::HTTPServer#start: pid=845 port=3000

Then when I got to generated page, it seems like it isn't working with sqlite3. How do I fix? Here's what the server prints out when I go to a scripted view page:

/!\ FAILSAFE /!\  Fri Aug 28 23:18:34 -0400 2009
  Status: 500 Internal Server Error
  uninitialized constant SQLite3::Driver::Native::Driver::API
    /Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:105:in `const_missing'
    /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/driver/native/driver.rb:76:in `open'
    /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/database.rb:76:in `initialize'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `new'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `sqlite3_connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `send'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in `checkout'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `loop'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `checkout'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in `checkout'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in `connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in `retrieve_connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `retrieve_connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in `connection'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/query_cache.rb:9:in `cache'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/query_cache.rb:28:in `call'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/head.rb:9:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/methodoverride.rb:24:in `call'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/params_parser.rb:15:in `call'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/session/cookie_store.rb:93:in `call'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/reloader.rb:29:in `call'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/failsafe.rb:26:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `synchronize'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `call'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/dispatcher.rb:106:in `call'
    /Library/Ruby/Gems/1.8/gems/rails-2.3.3/lib/rails/rack/static.rb:31:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:46:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in `each'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in `call'
    /Library/Ruby/Gems/1.8/gems/rails-2.3.3/lib/rails/rack/log_tailer.rb:17:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/content_length.rb:13:in `call'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/handler/webrick.rb:46:in `service'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/handler/webrick.rb:13:in `run'
    /Library/Ruby/Gems/1.8/gems/rails-2.3.3/lib/commands/server.rb:111
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3

If you upgraded from Leopard, then you will need to reinstall the sqlite3-ruby gem. First install XCode, then run:

sudo gem install sqlite3-ruby

如果从XCode安装程序安装UNIX Dev Tools,则应包含必要的头文件(ruby.h)。

sudo port install sqlite3 sudo gem install sqlite3-ruby

You should re-install XCode from the Snow Leopard DVD. This should fix the linkage problem!

I just ran into this problem. This is what I ended up doing:

rm -fr ~/.gem
sudo gem install rails
sudo gem install sqlite3-ruby

Now my rails/sqlite3 app is running again.

Another possible cause for this problem is continuing to use Ruby versions installed with rvm ( http://rvm.beginrescueend.com/ ) on Leopard after upgrading to Snow Leopard.

Ruby versions installed with rvm are built from source and needs to be reinstalled on Snow Leopard to work with the sqlite3-ruby gem.

I had a similar issue. If you look at the stack backtrace, you can see that the file throwing the error is within sqlite-ruby itself:

def open( filename, utf16=false )
  API.send( utf16 ? :sqlite3_open16 : :sqlite3_open, filename )
end

So the API class is missing. At top of this file is the following code which suggests that the API class comes from requiring the sqlite3_api file:

begin
  require 'sqlite3_api'
rescue LoadError
  if RUBY_PLATFORM =~ /mingw|mswin/ then
    RUBY_VERSION =~ /(\d+.\d+)/
    require "#{$1}/sqlite3_api"
  end
end

As you can see, this code will ignore a LoadError on platforms other than mingw/mswin. This is bad, and something I would consider a bug in the sqlite3-ruby gem. To figure out what's wrong, try requiring sqlite3_api in irb:

$ irb
irb(main):001:0> require 'sqlite3_api'
LoadError: Unable to find library 'libsqlite3.so.8'. - /path/to/ruby/lib/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.5/lib/sqlite3_api.sl
        from (irb):1:in `require'
        from (irb):1
        from /path/to/ruby/bin/irb:12:in `<main>'
irb(main):002:0>

YMMV, but for me, I realised that I was missing something in my shared-library path. Once I corrected that, everything worked.

For some reason, this didn't work too well for me.

I had to basically start from scratch, following these instructions: http://hivelogic.com/articles/ruby-rails-leopard from the "Setting Up" stage.

  • Install XCode
  • Download Ruby 1.8.7
  • Recompile and install (I think this was the magic step I was missing)
  • Download Rubygems 1.3.5 (1.3.6 has some things deprecated that I didn't want to deal with)
  • Recompile and install Rubygems
  • THEN uninstall sqlite3: sudo gem uninstall sqlite3-ruby
  • Reinstall it: sudo gem install sqlite3-ruby

To be clear, I tried the steps above. I tried installing XCode. I tried recompiling Rubygems...Only when I recompiled Ruby itself, THEN Rubygems, THEN uninstall and reinstall sqlite3-ruby did things clear up.

I hope this helps.

I've done all this... the only thing that has worked for me is

sudo env ARCHFLAGS="-arch x86_64" gem install sqlite3-ruby

Note: I did have XCode installed from devloper.apple.com, not the CD. The CD install of XCode Tools did nothing to fix this problem for me.

If you don't have any XCode installed, you may need to get XCode 3 or 4 from http://developer.apple.com/xcode . You will need to sign up for an account. Presently, you may download XCode 3 for free without paying the $99 annual fee.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM