You can also just stuff using: collection for render: partial. Which pass each element to a value for: collection for a local variable that shares the name of your partial.
<% @posts = GetAllPostsFunctions %> (removed for berivity) <%= render :partial => "posts/post_show", :collection => @posts %>
In this case, Rails will display post_show for each item in @posts with the local post_show variable set for the current item. It also provides convenient counter methods.
Successful use of this approach will require renaming the application / views / posts / _post_show.html.erb, partial to app / views / posts / _post.html.erb, or changing each instance of the post in your partial post_show. If you renamed partial to regular _post.html.erb, which then allows you to simply:
<%= render :partial => @posts %>
which will be partial for each individual post in the @posts variable.
Emfi
source share