Justin Meltzer
Justin Meltzer

Reputation: 13558

ActiveRecord::AssociationTypeMismatch when setting an association

This is the error:

ActiveRecord::AssociationTypeMismatch in VideosController#update
Topic(#2173382840) expected, got String(#2148246520)

It's from this method:

def assign_topics
    if @topic_names
      self.topics = @topic_names.each do |name|
        Topic.find_or_create_by_name(name)
     end
    end
  end

What is this error saying? I don't understand there being a type "topic" when topic is a model for me...

Upvotes: 0

Views: 529

Answers (1)

coder_tim
coder_tim

Reputation: 1720

"each" returns the original array or enumerable, try using "map" instead

Upvotes: 6

Related Questions