I have the following code in my seeds.rb file in a jruby 1.6.3 rails 3.1 project which I invoke with 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
When I run rake db:seed --trace , I get the following stack 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:开发者_C百科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
THis used to work, can anyone make any sense of what is going on? My gemfile looks like this:
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
Any help greatly appreciated.
This is a problem with the current version of activerecord-jdbc (1.1.3 as we speak).
Add this to your gem file and you should be good to go :
gem "activerecord-jdbc-adapter",
:git => "https://github.com/nicksieger/activerecord-jdbc-adapter.git"
Don't forget to switch back to the gem repo when activerecord-jdbc 1.1.4 is released.
精彩评论