Odd Behavior with render


#1

I’d been trying to iterate through an array of hashes using the
ActionController’s render method. Unfortunately, it appears that when
I use a hash as one of the array elements, it gets passed as a nil to
the partial. Here’s some code:

       @books = [ 'hello', 'hello2' ]
       render :partial => "book", :collection => @books

In this case, the partial gets called twice, and the local variable
‘book’ is populated with the values one would expect.

       @books = [ { 'title' => 'hello' }, { 'title' => 'hello2' }]
       render :partial => "book", :collection => @books

When I try to pass in hashes as the array elements above, the partial
still gets called twice, but the local variable ‘book’ is a nil
object, rather than the hash object I’d hoped for.

       @books = [ 'title' , { 'title' => 'hello2' }]
       render :partial => "book", :collection => @books

For the sake of completeness, the above calls the partial twice, with
‘title’ the first time and nil the second.

Does anybody have any idea why the behavior would be different in
these cases?

Thanks in advance for any insight.

Sean