TypeError: no implicit conversion of Hash into Integer

TypeError: no implicit conversion of Hash into Integer

这是设置我的变量并创建散列,然后我尝试从 json 对象创建用户并对密码进行硬编码,但我返回了一个错误。我收到 TypeError: 没有将 Hash 隐式转换为 Integer 我不太清楚为什么 json 文件不包含密码,我必须为每个用户硬编码一个

require 'json'
encrypted_password = '#$taawktljasktlw4aaglj'
file = File.read('db/people.json')
data_hash = JSON.parse(file)
records = JSON.parse(File.read('db/people.json'))

records.each do |record|
    records['encrypted_password' => encrypted_password]
    user = User.create!(record.except('logins'))
    user.logins.create(record['logins'])
end



不是直接设置 encrypted_password,而是设置 passwordpassword_confirmation,让 Devise 完成加密工作。这样,您的用户将获得您设置的默认密码。您的代码现在应如下所示:

require 'json'
password = 'temporary_password'
file = File.read('db/people.json')
data_hash = JSON.parse(file)
records = JSON.parse(File.read('db/people.json'))

records.each do |record|
    record['password'] = password
    record['password_confirmation'] = password
    user = User.create!(record.except('logins'))
    user.logins.create(record['logins'])
end