Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3681272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:40:18+00:00 2026-05-19T03:40:18+00:00

I’m trying to create a simple view helper but as soon as I try

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:40:19+00:00Added an answer on May 19, 2026 at 3:40 am

    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.

    <%= table_for(@users) do |t| %>
       <% t.col :name %>
       <% t.col :email %>
       <% t.col :test, :value => lambda { |u| u.email }, :th => 'Custom column name' %>
       <% t.col :static, :value => 'static value' %>
    <% end %>
    

    Using the output_buffer directly and probably reinventing the wheel the code looks like

    module ApplicationHelper
      def table_for(list, &block)
        table = Table.new(self)
        block.call(table)
        table.show(list)
      end
    
      class Column
        include ActiveSupport::Inflector
    
        attr_accessor :name, :options
    
        def initialize(name, options = {})
          @name    = name
          @options = options
        end
    
        def td_value(item)
          value = options[:td]
          if (value)
            if (value.respond_to?('call'))
              value.call(item)
            else
              value
            end
          else
            item[name]
          end
        end
    
        def th_value
          options[:th] ||= humanize(name)
        end
      end
    
      class Table
        include ActionView::Helpers::TagHelper
    
        attr_accessor :template, :columns
    
        def initialize(temp)
          @columns  = Array.new
          @template = temp
        end
    
        def col(name, options = {})
          columns << Column.new(name, options)
        end
    
    
        def show(list)
          template.content_tag(:table) do
            template.output_buffer << template.content_tag(:tr) do
              columns.collect do |c|
                template.output_buffer << content_tag(:th, c.th_value)
              end
            end
            list.collect do |item|
              template.output_buffer << template.content_tag(:tr) do
                columns.collect do |c|
                  template.output_buffer << template.content_tag(:td, c.td_value(item))
                end
              end
            end
          end
        end
    
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.