Reputation: 35
this is setting my varibles and creating the hash I then try to create the users from json objects and hardcode a password but im returned an error. Im getting a TypeError: no implicit conversion of Hash into Integer and im not quite sure why the jsonfile does not contain a password and i must hard code one for each user
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
Upvotes: 1
Views: 3562
Reputation: 177
Instead of directly setting encrypted_password
, set password
and password_confirmation
instead and let Devise do the job of encryption. This way, your users will get a default password that you set. Your code now should look as follows:
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
Upvotes: 1