Forum: Ruby on Rails Helper causes view output to be duplicated

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.
5562ed3d0ad00a2265f66f6fff2bb0bf?d=identicon&s=25 dom (Guest)
on 2005-11-26 15:49
(Received via mailing list)
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,
5562ed3d0ad00a2265f66f6fff2bb0bf?d=identicon&s=25 dom (Guest)
on 2005-11-26 16:22
(Received via mailing list)
On Saturday 26 November 2005 14:45, Dominic Marks 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 :)
This topic is locked and can not be replied to.