ruby on rails - Define csv attribute dynamically -
Below is a CSV importer. It's working perfectly but I dynamically define it by defining the speed Want to
How do I change the attribute "name" with attribute that I define before the execution of CSV?
For example: - Name: line [1] - & gt; Name: Line [attribute] In the above example, "an underlying conversion in the integer string of error" is stated, which is clearly true.
Below is the code. import_attribute = import_dimension.import_attributes.first attribute = import_attribute.name csv Forch (Rails.root.join ('tmp', 'uploads', csv_path), col_sep: import_source.csv_delimiter, line_sap :: auto, skip_bucks: true, header: false). Line | target.create Company: self.import_source.company, code: line [0], name: line [1] termination
You can use a hash that maps the attribute to the array in its position.
status = {code: 0, name: 1} and then
target.create Company: self.import_source.company, code: line [post [[code]], name: line [word [[name]]
Comments
Post a Comment