Forum: Ruby on Rails can't get render... :collection to work ??

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2006-04-11 18:48
(Received via mailing list)
Hi all -

New to Rails so I'm hoping this is something obvious, but I can't get it
to work.  Here's my view:

----------------------------------------------------------------------
<% @search.results.each do |r| %>
         <%= render :partial => 'result', :locals => {:result => r} %>
         <%= render :partial => 'result_divider' %>
<% end %>

<%= render :partial => 'result', :collection => @search.results,
 		:spacer_template => 'result_divider' %>
----------------------------------------------------------------------

_result.html looks like this:
----------------------------------------------------------------------
<%= result[:url] %>
----------------------------------------------------------------------

_result_divider.rhtml contains "<hr>".

If I remove the last render() call the page prints out the url field
separated by <hr>'s just like I'd expect.  If I include that last
render()
call I get an error pointing to _result.html:

----------------------------------------------------------------------
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.[]
----------------------------------------------------------------------

What I don't understand is why the first works, but not the second since
my understanding is that first each() loop is really the same thing as
the
second render() call.

???

Thanks!

-philip
This topic is locked and can not be replied to.