# Passing blocks to partials

**URL:** <https://www.ruby-forum.com/t/passing-blocks-to-partials/161674>\
**Category:** Rails\
**Created:** [February 28, 2009, 9:20pm UTC](https://www.ruby-forum.com/t/passing-blocks-to-partials/161674 "2009-02-28T21:20:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevo84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f14d63/32.png) [@stevo84](https://www.ruby-forum.com/u/stevo84)\
**Post date:** [February 28, 2009, 9:20pm UTC](https://www.ruby-forum.com/t/passing-blocks-to-partials/161674/1 "2009-02-28T21:20:25Z")

</div>

Hi  
I’ve got following problem:

I am attempting to write helper that will display table (stored in  
partial) with some custom last column contents.

I would like to call it like

\<% parametrized\_users\_list(@users) do |user| %\>  
\<%= user.id %\>  
\<%= user.created\_at %\>  
\<% end %\>

where user.id and user.created\_at would be that custom last column  
content

What I did was I’ve created helper

def parametrized\_users\_list(users, options = {}, &block)  
concat( render(:partial =\> ‘users/users\_list’, :locals =\>  
options.merge(:users =\> users, :optionals =\> block)) )  
end

and partial

 \<% users.each do |user| %\> \<% end %\> 

| Username | Email | |
| --- | --- | --- |
| \<%=h user.nickname %\> | \<%=h user.email %\> | \<%= optionals.call(user) %\> |

… but as I render it, it results in a lot of trash - whole table is  
rerendered within itself several times etc… What did I do wrong? How  
can I store this erb to later render it in partial with correct  
context (user in this case)…

---

<div class="post-metadata">

**Author:** ![stevo84](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f14d63/32.png) [@stevo84](https://www.ruby-forum.com/u/stevo84)\
**Post date:** [February 28, 2009, 9:58pm UTC](https://www.ruby-forum.com/t/passing-blocks-to-partials/161674/2 "2009-02-28T21:58:40Z")

</div>

Solved…

I’ve changed

\<%= optionals.call(user) %\>  
to  
\<%= with\_output\_buffer {optionals.call(user)} %\>

and now it works… Probably if I knew how to pass params (user) to  
capture helper, I could use that instead
