My issue involves an array that is apparently not nil but when I try to access it, it is.
The array is returned from a find on an active record. I have confirmed it is in fact an array with the .class method
@show_times = Showing.find_showtimes(params[:id]) @show_times.inspect =>shows that the array is not empty and is a multidimensional array. @show_times[0] =>is nil @show_times[1] =>is nil @show_times.first.inspect => NoMethodError (undefined method `first')
I am perplexed as to why this is..
find_showtimesis not a built-in finder – if it were, it would return either a single ActiveRecord object or an array of ActiveRecord objects – never a multidimensional array. So the first thing I’d do is have a look a the source of that method.EDIT: Given your source code (in the comment) – you’re actually getting a Hash, not an Array, back from your finder. See the docs for Enumerable’s group_by. The Hash is mapping your theater objects to an array of showing objects. This is what you want to do: