= table_helper +table_helper+ adds a helper method for generating HTML tables from collections. == Resources API * http://api.pluginaweek.org/table_helper Bugs * http://pluginaweek.lighthouseapp.com/projects/13290-table_helper Development * http://github.com/pluginaweek/table_helper Source * git://github.com/pluginaweek/table_helper.git == Description Tables of summary data for ActiveRecord models are often formatted in the same way by creating a header indicating the attribute and a body containing the data from each record in separate rows. table_helper makes it easier to create these types of tables by DRYing much of the html being generated. == Usage === Basic Example <%= collection_table Person.find(:all) %> ...is compiled to (formatted here for the sake of sanity):
First Name Last Name Company Role
John Doe 1 President
Jane Doe 1 Vice-President
=== Advanced Example <%= collection_table(@posts, :id => 'posts', :class => 'summary') do |t| t.header :title t.header :category t.header :author t.header :publish_date, 'Date
Published' t.header :num_comments, '# Comments' t.header :num_trackbacks, '# Trackbacks' t.rows.alternate = :odd t.rows.each do |row, post, index| # Notice there's no need to explicitly define the title row.category post.category.name row.author post.author.name row.publish_date time_ago_in_words(post.published_at) row.num_comments post.comments.empty? ? '-' : post.comments.size row.num_trackbacks post.trackbacks.empty? ? '-' : post.trackbacks.size end t.footer :num_comments, @posts.inject(0) {|sum, post| sum += post.comments.size} t.footer :num_trackbacks, @posts.inject(0) {|sum, post| sum += post.trackbacks.size} end %> ...is compiled to (formatted here for the sake of sanity):
Title Date
Published
# Comments # Trackbacks
Open-source projects: The good, the bad, and the ugly 23 days - -
5 reasons you should care about Rails 21 days - -
Deprecation: Stop digging yourself a hole 17 days - -
Jumpstart your Rails career at RailsConf 2007 4 days - -
Getting some REST about 18 hours - -
0 0
=== Caveat Emptor See the API for more information on syntax, options, and examples. You should only use table_helper if it fits the needs of your application. Remember one of the key principles of Rails, KISS (Keep It Simple Stupid). table_helper works really well when you need to quickly output several of these types of summary tables. If this is not the case, you may want to stick to using actual html. == Testing Before you can run any tests, the following gem must be installed: * plugin_test_helper[http://github.com/pluginaweek/plugin_test_helper] To run against a specific version of Rails: rake test RAILS_FRAMEWORK_ROOT=/path/to/rails == Dependencies * Rails 2.0 or later