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

table_helper

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

table_helper

  • 0.2.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= table_helper

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

== Resources

API

  • http://api.pluginaweek.org/table_helper

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 07 Mar 2010

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc