Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

tangofoxtrot-table_helper

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tangofoxtrot-table_helper


Version published
Maintainers
1
Created

= table_helper

+table_helper+ adds a helper method for generating HTML tables from collections.

== Resources

API

Bugs

Development

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 NameLast NameCompanyRole
JohnDoe1President
JaneDoe1Vice-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<br >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):

TitleCategoryAuthorDate
Published
# Comments# Trackbacks
Open-source projects: The good, the bad, and the uglyGeneralJohn Doe23 days--
5 reasons you should care about RailsRailsJohn Q. PUblic21 days--
Deprecation: Stop digging yourself a holeRailsJane Doe17 days--
Jumpstart your Rails career at RailsConf 2007ConferencesJane Doe4 days--
Getting some RESTRailsJohn Doeabout 18 hours--
00

=== 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:

To run against a specific version of Rails:

rake test RAILS_FRAMEWORK_ROOT=/path/to/rails

== Dependencies

  • Rails 2.0 or later

FAQs

Package last updated on 10 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts