I’m trying to create a simple view helper but as soon as I try nest a couple of content tags it will throw
NoMethodError: undefined method `output_buffer=' for
def table_for(list, &proc)
t = Table.new
proc.call(t)
t.render_column(list)
end
class Table
include ActionView::Helpers::TagHelper
attr_accessor :columns, :block
def initialize
@columns = Array.new
end
def col(name)
@columns << name
end
def render_column(list)
content_tag :table do
list.each do |c|
content_tag :td, c
end
end
end
end
Any hints of what’s wrong? I’ve also seen that there’s a XmlBuilder is that one better for my purpose?
With help from Nested content_tag throws undefined method `output_buffer=` in simple helper I ended up with the following solution inspired by the API for Formtastic.
Using the output_buffer directly and probably reinventing the wheel the code looks like