lib/config_scripts/seeds/seed_type.rb
# This method reads the seed data from a file, and creates new records
# from it.
#
# This will extract all the rows from the CSV file, and use
# {#read_value_for_attribute} to get the attributes for the record from
# each cell in the CSV file.
#
# If this seed type has no attributes, this method will not try to read
# the file.
#
# @param [String] folder
#   The full path to the folder with the seed files.
This method reads the seed data from a file, and creates new records
from it.

This will extract all the rows from the CSV file, and use
{#read_value_for_attribute} to get the attributes for the record from
each cell in the CSV file.

If this seed type has no attributes, this method will not try to read
the file.
This method reads the seed data from a file and creates new records from it . This will extract all the rows from the CSV file and use { #read_value_for_attribute } to get the attributes for the record from each cell in the CSV file . If this seed type has no attributes this method will not try to read the file .
def read_from_folder(folder)
        return unless attributes.any?
        CSV.open(File.join(folder, "#{self.filename}.csv"), headers: true) do |csv|
          csv.each do |row|
            record = self.klass.new
            row.each do |attribute, value|
              attribute = attribute.to_sym
              value = self.read_value_for_attribute(value, attribute)
              record.send("#{attribute}=", value)
            end
            begin
              record.save!
            rescue
              puts "#{self.filename}.csv"
              raise
            end
          end
        end
      end
def read_from_folder ( folder ) return unless attributes . any? CSV . open ( File . join ( folder , "#{self.filename}.csv" ) , headers : true ) do | csv | csv . each do | row | record = self . klass . new row . each do | attribute , value | attribute = attribute . to_sym value = self . read_value_for_attribute ( value , attribute ) record . send ( "#{attribute}=" , value ) end begin record . save! rescue puts "#{self.filename}.csv" raise end end end end
This method reads the seed data from a file, and creates new records
from it.
This method reads the seed data from a file and creates new records from it .
folder
<not_specific>
<not_specific>
folder The full path to the folder with the seed files.
folder The full path to the folder with the seed files .