I'm trying to create a song with associated tags, but my create method throws an error:
Tag(#70267554396440) expected, got String(#70267493763880)
My Songs#create:
def create
tags = params[:song][:tag_list].split(", ")
@song = current_user.songs.create(song_params)
tags.each do |tag|
if Tag.find_by(:name => tag)
@song.tags << tag
else
@song.tags.create(:name => tag)
end
end
flash[:success] = "You have successfully created a new track!"
redirect_to @song
end
What should I do? The issue seems to be with adding an existing tag to the song.