In the following two lines:
others = Material.find_all_by_original_name(self.original_name)
if others.length == 0 || (others.length == 1 && others.id == self.id)
The word "length" is underlined as wrong the first time it appears on that line, but not the second time. This same construct is used in two different places with two different models.
The message is:
Cannot find 'length' for type 'Array of Material'