I am getting:
syntax error, unexpected '=', expecting keyword_end diamond.send(field) = fields[field]
But I don't see why though. I am trying to dynamically assigning values.
Here is the code:
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
diamond = find_by_id(row["id"]) || new
fields = row.to_hash
# assign non float attributes to columns
['cust_ref', 'ags_1st_number', 'ags_ending_number', 'gold_cut_grade',
'polish_grade', 'symmetry_grade', 'color_grade', 'fluor_desc',
'clarity_grade', 'girdle_min_max_percentage', 'diameter_min_max',
'girdle_condition', 'proportion_grade', 'comment_1', 'comment_2',
'comment_3', 'comment_4', 'is_non_ideal', 'key_to_symbols', 'shape'].each do |field|
diamond.send(field) = fields[field]
end
end
end
diamond.send(field + '=', fields[field])I think.. Because the way you are assigning is not valid.