我在jruby 1.6.3 rails 3.1项目中的seeds.rb文件中有以下代码,我用rake db:seed
调用Role.destroy_all
User.destroy_all
["admin", "standard"].each do |role|
Role.find_or_create_by_name(role)
end
if User.find_by_email("dagda1@scotalt.net").nil?
user = User.new
user.email = "dagda1@scotalt.net"
user.password = "Passw0rd"
user.password_confirmation = "Passw0rd"
user.role = Role.find_by_name("admin")
user.save!
end
if User.find_by_email("fiblevins@hotmail.com").nil?
user = User.new
user.email = "fiblevins@hotmail.com"
user.password = "bonjovi5"
user.password_confirmation = "bonjovi5"
user.role = Role.find_by_name("standard")
user.save!
end
当我运行rake db:seed --trace时,我得到以下堆栈跟踪:
** Invoke db:seed (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:seed
rake aborted!
wrong number of arguments (3 for 2)
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/activerecord-3.1.0.rc5/lib/active_record/base.rb:470:in `find_by_sql'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/activerecord-3.1.0.rc5/lib/active_record/relation.rb:111:in `to_a'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/activerecord-3.1.0.rc5/lib/active_record/relation.rb:289:in `destroy_all'
org/jruby/RubyBasicObject.java:1684:in `__send__'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/activerecord-3.1.0.rc5/lib/active_record/base.rb:438:in `destroy_all'
/Users/paulcowan/projects/leadcapturer/db/seeds.rb:3:in `(root)'
org/jruby/RubyKernel.java:1073:in `load'
/Users/paulcowan/projects/leadcapturer/db/seeds.rb:233:in `load'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:639:in `new_constants_in'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:638:in `new_constants_in'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:233:in `load'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/railties-3.1.0.rc5/lib/rails/engine.rb:487:in `load_seed'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/activerecord-3.1.0.rc5/lib/active_record/railties/databases.rake:299:in `(root)'
org/jruby/RubyProc.java:256:in `call'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute'
org/jruby/RubyArray.java:1603:in `each'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/Users/paulcowan/.rvm/rubies/jruby-1.6.3/lib/ruby/1.9/monitor.rb:201:in `mon_synchronize'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
org/jruby/RubyArray.java:1603:in `each'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:62:in `run'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/gems/rake-0.9.2/bin/rake:32:in `(root)'
org/jruby/RubyKernel.java:1073:in `load'
/Users/paulcowan/.rvm/gems/jruby-1.6.3/bin/rake:19:in `(root)'
Tasks: TOP => db:seed
过去常常工作,任何人都可以了解发生了什么事吗?我的gemfile看起来像这样:
source 'http://rubygems.org'
source 'http://gems.engineyard.com'
gem 'rails', '~> 3.1.0.rc5'
gem 'sass-rails'
gem 'compass', git: 'https://github.com/chriseppstein/compass.git',branch: 'rails31'
gem 'fancy-buttons'
gem 'haml'
gem 'authlogic', :git => 'https://github.com/AndreasWurm/authlogic.git'#, :branch => 'rails3'
gem 'nokogiri'
gem 'bundler'
gem 'resque'
gem 'resque-meta'
gem 'jquery-rails'
gem 'rake'#, '~> 0.8.7'
gem 'eventmachine'
gem 'em-websocket'
gem 'json'
gem 'coffee-script'
gem 'uglifier'
platforms :jruby do
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcsqlite3-adapter'
gem 'jruby-openssl'
gem 'jdbc-mysql'
gem 'jruby-rack'
gem 'warbler'
#gem 'glassfish', '1.0.3.dev'
end
group :test, :development do
platforms :jruby do
gem 'jdbc-sqlite3', :require => false
gem 'fastercsv'
gem 'ruby-debug'
end
platforms :ruby do
gem 'sqlite3-ruby', :require => 'sqlite3'
end
gem 'mocha'
gem 'factory_girl'
gem 'fakeweb'
gem 'shoulda', :require => 'shoulda'
end
非常感谢任何帮助。
答案 0 :(得分:1)
这是当前版本的activerecord-jdbc(我们说的是1.1.3)的问题。
将此添加到您的gem文件中,您应该好好去:
gem "activerecord-jdbc-adapter",
:git => "https://github.com/nicksieger/activerecord-jdbc-adapter.git"
当activerecord-jdbc 1.1.4发布时,不要忘记切换回gem repo。