Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A DSL and output framework for defining views consisting of tables that can output to HTML, CSV, XLS or ascii.
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


Tableview is a gem to be used in Rails to create table like views.


In your Gemfile:

gem 'tableview'


$ bundle install
$ rails g tableview:install


To apply to a resource use the built in generator:

$ rails g tableview resource_name

This will create a partial named in which you can use a DSL like this to define your table:

=> @registrations

+ :first_name
+ :surname
+ :address {|reg| reg.address + "\n" + reg.postcode }
+ :friends if format.html?

if format.xls?
  = @registrations.some_scope, "Workbook title"
  = @registration.other_scope, "Works as title in other formats as well"


The DSL is a simple superset of ruby with a few special characters (only work if first printable character on line, won't work with eval and friends).

Character Meaning
=> Use the passed collection for rendering and I18n
* Pass a hash to this, is used to configure the formatters.
+ Defines a column. If passed a symbol, Tableview will use I18n to lookup the header and call the method on the model to get the value. Strings will be used literally. Optionally use a block to generate values.
= Render a subtable for the passed collection. Not all formatters support subtables, use at own risk (notably the CSV formatter has no support for this). Is meant mainly to have nice full-featured excel files.

What if I don't like the DSL?

You may simply create a .rb file instead, it will just have to include some boilerplate code (same result as above):

format =
tv = Tableview::ViewHandler.table do |table|
  table.table_for @registrations

  table.column :first_name
  table.column :surname
  table.column :address {|reg| reg.address + "\n" + reg.postcode }
  table.column :friends if format.html?

  if format.xls?
    table.generate_subtable_for @registrations.some_scope, "Workbook title"
    table.generate_subtable_for @registration.other_scope, "Works as title in other formats as well"
output = Tableview::output_class(params[:format]).new

It will also add a few lines of code to your controller:

  • self.responder = ApplicationResponder this sets up the correct code path to use for dynamically rendering all the formats.
  • respond_to :html, :json, :csv, :xls, :ascii a list of supported formats. You will want to use respond_with as well.
Something went wrong with that request. Please try again.