https://github.com/bodrovis-learning/RailsSeriesYT/blob/lesson_11/app/services/user_bulk_service.rb line 15 and 26
def callZip::File.open(@archive) do |zip_file| zip_file.glob('*.xlsx').each do |entry| User.import users_from(entry), ignore: true endend
:
def users_from(entry) sheet = RubyXL::Parser.parse_buffer(entry.get_input_stream.read)[0] sheet.map do |row| cells = row.cells[0..2].map { |c| c&.value.to_s } User.new name: cells[0], email: cells[1], password: cells[2], password_confirmation: cells[2] end
How does users_from return array for User.import while it return user in loop? There no yield function. It s logical that it will return only one last element