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: _start_box.erb ---------------- <table id="box" width="<%= width %>"><tr><th><%= h(label_text) %></th></tr><tr><td> _end_box.erb ---------------- </td></tr></table> The to use it my_form.erb ---------------- %= render :partial => "start_box", :locals => { :label_text => "Box Label", :width => "97%" } %> <b>Some Text</b><br /> <b>Some More Text</b><br /> <b>Some More Text</b><br /> <b>Some More Text</b> <%= render :partial => "_end_box" %> Then use some CSS to purdy it up. 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 table? Thanks swoolley-a1UlTwdHLosxpvK4C0GaPQ@public.gmane.org -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 > table?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 end 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 %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Beautiful, beautiful, beautiful... works like a champ. Thanks for your help! Mark Bush wrote:> > 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 > end > > 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 %>-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---