Forum: Ruby on Rails Odd Behavior with render

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Sean McMains (Guest)
on 2005-12-27 08:04
(Received via mailing list)
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.

This topic is locked and can not be replied to.