In Rails, how can I pass a parameter to the `capture` method?

In the Rails helper, you can capture output of an ERB block using the capture method. However, what if a parameter is required for the ERB block? How can I use capture in this case?

For the given example:

 <% my_helper(:parameter, models) do |model| %> <%= model.eye_color %> <% end %> 

In the my_helper method my_helper I want to surround the output of each iteration of the <span class='color'>...</span> block.

I know that I can capture the output of an ERB block and save it in a variable using html = capture(&block) , but I do not know how to pass this model parameter to this block!

+4
source share
1 answer

Can you pass them on to the call for capture? The docs show that it separates the arguments, so I would suggest that they are passed in a block. For instance:

 html = capture(:foo, :bar, &block) 
+9
source

All Articles