Writing out a rake task to import from csv, one would tend to write
Article.create(
category_id: row[0],
label: row[1],
name: row[2],
integer: row[3],
priority: row[4]
)
But these need to be refactored taking into account a meta-structure where
Class Import
has_many :importattributes
The following is syntactically incorrect
Article.create(
import.importattributes.each do |importattribute|
m_attr = importattribute.mapped_attribute
sequence = importattribute.position.to_i
m_attr: row[sequence]
end
)
on the line complaining about syntax error, unexpected ':', expecting 'end'
m_attr: row[sequence] If that line is commented out, other actions run as they do not parse this error beforehand.
I assume this is mistaken for the proper creation of array of attributes, because an update action, on a per attribute basis
import.importattributes.each do |importattribute|
m_attr = importattribute.mapped_attribute
sequence = importattribute.position.to_i
Article.update(m_attr: row[sequence])
end
does not raise the error.