Slide 31
Slide 31 text
def save!
return false unless valid?!
!
User.transaction do!
CSV.read(path, "r", CSV_OPTIONS).each_with_index do |row, index|!
user = User.new(!
! ! ! email: row[0], !
! ! ! first_name: row[1], !
! ! ! last_name: row[2]!
! ! )!
unless user.save!
errors.add(!
! ! ! ! "line #{index+1} : ", !
! ! ! ! user.errors.full_messages.join(" , “)!
! ! ! )!
end!
end!
!
if errors.any?!
raise ActiveRecord::Rollback!
end!
end!
!
!errors.any?!
end
user_import.rb