Just raw code at the moment.  This may evolve into a helper example, if people are interested.

<pre style="overflow:scroll"><code>
# The methods added to this helper will be available to all templates in the application.
class Hash
    def /(key)
        reject { |k,v| key === k }
        end
    end

module ApplicationHelper
    def magic_rows(what,options={},&block)
        if what.respond_to? :collect
            what.collect { |item| magic_rows(item,options,&block) }.join("\n")
          else
            magic_row(what,options,&block)
          end
        end
    def magic_row(what,options={},&block)
        unless options[:columns]
            t = (what.is_a? Class) ? what : what.class
            options[:skip_columns] = (options[:skip_columns] || []).collect { |c| c.to_s }
            options[:columns] = (
                (t.respond_to?       :edit_columns)    ? t.edit_columns :
                (t.respond_to?       :columns)         ? t.columns.reject { |c| [t.primary_key,t.inheritance_column,'created_on','updated_on','lock_version'].include? c.name || c.name =~ /_count$|^created_on$/ } :
                (t.respond_to?       :content_columns) ? t.content_columns :
                (what.respond_to?    :to_s)            ? [Column.new(:to_s)] :
                [Column.new(:inspect)]
              ).reject { |c| options[:skip_columns].include? c.name }
            end
        s = if what.is_a? Class
            header_row(what,options)
          elsif options[:edit]
            unique_id = 5
            result = %Q{
                <div>#{data_row what,options}<a onClick=''>edit</a></div>
                <div>#{edit_row what,options}</div>
                }
          else
            data_row(what,options)
          end
        "<tr>#{block_given? ? block.call(what,s) : s}</tr>"
        end
    def magic_table(what,options={},&block)
        case options[:embedded]
          when :new_row
            "</tr><tr><td colspan='10'>#{magic_table(what,options/:embedded,&block)}</td>"
          else
            %Q{<table #{options[:table]}>
                #{magic_rows(what,options,&block)}
                </table>}
          end
        end
    def header_row(what,options)
        options[:columns].collect { |column|
            "<th>#{column.human_name.sub(/ id$/,'')}</th>"
            }.join+
          "<th>&nbsp;</th>"*(options[:buttons] || []).length
        end
    def data_row(what,options={})
        options[:columns].collect { |column|
            "<td>#{if column.name =~ /(.*)_id$/ and what.respond_to? $1.intern
                v = what.send($1)
                text = if      v.respond_to? :name   then v.name
                  elsif v.respond_to? :to_s   then v.to_s
                  else                             what.send(column.name)
                  end
                link_to text, :controller => v.class.to_s.downcase, :action => 'show', :id => v
              elsif what.respond_to? column.name
                what.send(column.name).to_s
              else
                "#{what}.#{column.name}"
              end}</td>"
            }.join+
         (options[:buttons] || []).collect { |button|
            case button
              when :show    then "<td>#{link_to 'Show', :action => 'show', :id => what}</td>"
              when :edit    then "<td>#{link_to 'Edit', :action => 'edit', :id => what}</td>"
              when :destroy then "<td>#{link_to 'Destroy', {:action => 'destroy', :id => what}, :confirm => "Are you sure?"}</td>"
              else               "<td>#{button}</td>"
              end
            }.join
        end
    def edit_row(what,options={})
        %Q{<form>
            #{options[:columns].collect { |column| "<td>#{column.human_name}</td>" }.join}
            </form>
            }
        end
    end


</code></pre>

Category: Stub
