Rails and Partials

Excuse my ignorance on partials but.....

I am trying to use partials to create a uniform display box built with
html tables. The only way I have thought about accomplishing this is to
create two partials:


Steve Woolley wrote:

This does seem to be a bit laborious when it seems partials are so
flexible. Should I be using partials for this type of widget? Is their
some way to accomplish this via a single partial instead of a partial
for the first part of the table and a partial for the end part of the

Use a helper instead. Something like:

def tablize options = {}, &block
  # Set some default values
  options[:width] ||= '100%'
  options[:label] ||= 'Box Label'
  header = content_tag(:tr, content_tag(:th, h(options[:label])))
  body = content_tag :tr, content_tag(:td, capture(&block))
  table = content_tag :table, header+body,
                 :id => :box, :width => options[:width]
  concat table, block.binding

Then in your views you can do:

<% tablize :width => '97%', :label => 'A Label' do %>
  <b>Some Text</b><br />
  <b>Some More Text</b><br />
  <b>Some More Text</b><br />
  <b>Some More Text</b>
<% end %>

Beautiful, beautiful, beautiful...

works like a champ. Thanks for your help!

Mark Bush wrote: