I am not sure how to present my issue best without posting the whole framework.
I have a method duplicate!
which should duplicate an object (channel). Usually it works but there is one channel where the method fails and I just don't understand why:
def duplicate!
channel = Channel.new do |c|
c.title = title << ' (copy)'
c.description = description
end
channel.nodes += nodes
playlist.nodes.each { |n| channel.playlist.playlist_items.create(node: n) }
channel
end
As said nearly all channels duplicate without a problem, but now I have one channel which fails to get duplicated:
2.3.0 :002 > channel.duplicate!
NoMethodError: undefined method `playlist_items' for nil:NilClass
from /var/www/app/models/channel.rb:110:in `block in duplicate!'
from /var/www/app/models/channel.rb:110:in `each'
from /var/www/app/models/channel.rb:110:in `duplicate!'
Every Channel has Nodes and a Playlist, the error producing Channel has too. I don't really understand the error; how can this method fail depended on the object to duplicate?