Gallery has_many photos. Photos belongs_to gallery
In my photo 'show' view I get the error 'undefined method `name' for nil:NilClass' for the line
<%= @photo.gallery.name %>
the error only appears on photos that aren't part of a gallery (that don't have a gallery name assigned to them) the ones that do, appear as expected i.e the gallery name is shown that it belongs to. The api says "Ruby raises NoMethodError if you invoke a method on an object that does not respond to it" but shouldn't the photo object respond to gallery.name even though it's empty?? as the models are properly associated...