0

一段时间以来,我一直在使用 rake 测试出错,所以我继续尝试使用固定装置输入数据,但我遇到了类似的错误,我不确定我哪里出错了。

[pears:]$ rake db:fixtures:load --trace
** Invoke db:fixtures:load (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:fixtures:load
rake aborted!
can't convert Symbol into Integer
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/bcrypt-ruby-3.0.1/lib/bcrypt.rb:160:in `[]'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/bcrypt-ruby-3.0.1/lib/bcrypt.rb:160:in `create'
(erb):7:in `<main>'
/Users/jake/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/erb.rb:838:in `eval'
/Users/jake/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/erb.rb:838:in `result'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures/file.rb:51:in `render'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures/file.rb:43:in `rows'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures/file.rb:29:in `each'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:670:in `block (2 levels) in read_fixture_files'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures/file.rb:20:in `open'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:669:in `block in read_fixture_files'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:668:in `each'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:668:in `read_fixture_files'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:548:in `initialize'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:482:in `new'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:482:in `block (2 levels) in create_fixtures'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:479:in `map'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:479:in `block in create_fixtures'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:232:in `disable_referential_integrity'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/fixtures.rb:476:in `create_fixtures'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:322:in `block (4 levels) in <top (required)>'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:321:in `each'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:321:in `block (3 levels) in <top (required)>'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/jake/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/bin/rake:19:in `load'
/Users/jake/.rvm/gems/ruby-1.9.3-p286@global/bin/rake:19:in `<main>'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/bin/ruby_noexec_wrapper:14:in `eval'
/Users/jake/.rvm/gems/ruby-1.9.3-p286/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:fixtures:load

我不确定它是否与我的 users.yml 文件有关...

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

<% SALT = "NaCl" unless defined?(SALT) %>

one:
  email: jake@test.com
  hashed_password: <%= BCrypt::Password.create('fresh', SALT) %> 
  salt: <%= SALT %>

two:
  email: james@test.com
  hashed_password: <%= BCrypt::Password.create('fresh', SALT) %> 
  salt: <%= SALT %>

不确定从哪里开始寻找解决方案。谢谢!

4

1 回答 1

0

您对 BCrypt 的使用无效...

BCrypt::Password.create('fresh', SALT)

文档说:

  # @password = BCrypt::Password.create("my secret", :cost => 13)
  def create(secret, options = { :cost => BCrypt::Engine::DEFAULT_COST })
    raise ArgumentError if options[:cost] > 31
    Password.new(BCrypt::Engine.hash_secret(secret, BCrypt::Engine.generate_salt(options[:cost]), options[:cost]))
  end

正确用法:

BCrypt::Password.create('fresh', :cost => 15) # any number less than 15
于 2012-11-17T00:43:10.640 回答