Helper causes view output to be duplicated


#1

Hello,

I wrote the following helper:

module SelectProductHelper
def select_product(object, method, products, options = {})
html = ‘’
brands = {}
products.each do |p|
if brands[p.brand_id] == nil
brands[p.brand_id] = p.brand.name
end
html<< content_tag(‘option’, “#{brands[p.brand_id]} - #{p.name}”,
{:value => p.id})
end
Binding.of_caller do |binding|
concat(content_tag(‘select’, html, {‘name’ =>
“#{object}[#{method}]”}), binding)
end
end
end

When included in a view this helper causes the entire view to be
rendered once and output twice. If I put a break statement after
the concat method, it works as expected.

So my question is, where did the other binding come from?

Most of my information regarding helpers comes from:

http://wiki.rubyonrails.com/rails/pages/HowtoWorkWithHelpers

Thanks,


#2

On Saturday 26 November 2005 14:45, Dominic M. wrote:

    brands[p.brand_id] = p.brand.name

rendered once and output twice. If I put a break statement after
the concat method, it works as expected.

So my question is, where did the other binding come from?

This was caused by me using <%= select_product … -%> rather than
<%%> as explained to me on IRC.

Most of my information regarding helpers comes from:

http://wiki.rubyonrails.com/rails/pages/HowtoWorkWithHelpers

Soon to be updated :slight_smile: