ActionTabler provides a drop in table action for your Rails controllers using DataTables.


  1. Add to your Gemfile:

    gem 'action_tabler'
  2. Install the gem:

    bundle install
  3. Include the datatables javascript in application.js:

    //= require action_tabler
  4. Include the datatables css in application.css

     *= require action_tabler


Once you've installed ActionTabler, you can add a fully functional table page to a resource.

  1. Define a table-enabled resourceful route for your controller:

     resources_with_tables :your_thing
  2. Add a declaration to your_thing_controller.rb:

     has_table_action :created_at, :title
  3. Start your server and navigate to "your_thing/table"


The following options can be configured with a Rails initializer:

  • action_tabler_columns: Array of column specifications. See complete documentation below. Default is nil.
  • action_tabler_table_class: Table html class. Default is nil.
  • action_tabler_auto_width: Datatables auto width setting. Default is true.
  • action_tabler_action: The controller action name for a table. Default is "table".
  • action_tabler_auto_type: Automatically populate datatables column types based on Rails column introspection. Default is true.
  • action_tabler_pass_params: Use request paramters associated with the table resource (eg. "[customers]last_name=Smith") to pre-filter the table data. Default is false, in a trade off of less magic for more security.
  • action_tabler_table_options: Additional DataTables table options, features and callbacks. See the has_table_action :table_options documentation below. Default is empty.

All of these options can be overridden by the has_table_action or action_tabler_options declarations.

has_table_action(columns, opts)

The has_table_action declaration will add a table display action to a controller.


The column parameter describes what will be displayed in your table.

It is either an array or the symbol :auto.

When :auto, ActionTabler will use reflection to display all of the resource's columns in the table it generates. Use of this option is strong discouraged, but can be used to just make somthing happen, even if it happens insecurely.

An array will define a list of columns to display.

A string or symbol in an array will add the corresponding model attribute or method using the default column options.

You can customize a particular column's options by passing a hash. Each hash can or should have the values below (DataTables equivalents are given in parenthases):

  • name: The attribute name. This can be a relationship attribute. For example, if you have an order which belongs to a customer which has a name attribute, you can specify "". (mDataProp and sName) Required.
  • label: The table column heading for this attribute. Default is the attribute name will be titleized. (sName)
  • searchable: Include this column in search box calls. Default is true. (bSearchable)
  • sortable: Provide sort controls for this column. Default is true. (bSortable)

Options not listed above will be passed through to DataTables, so that you can access options like sClass, sWidth, or sVisible. For the special handling of the sType column, see the :auto_type option below. For more on the special handling of DataTables fn or m options see the "Datatables fn and m Options" below.

You can learn more about DataTable column options in the DataTables Column Usage documentation.

This parameter can either be passed as the first argument or as a block. For example:

    has_table_action [:first_name, :last_name], :pass_params => true


    has_table_action(:pass_params => true) do
      column :title
      column :author,
      column :created_at, :label => "Entered", :searchable => false

:action option

Unless specified otherwise in your Rails configuration, ActionTabler assigns it's table display method to a method called "table." You can override this with the action option, with something like "index," for example.

:auto_type option

Specify whether to populate your column definitions with DataTable's data types using Rails reflections. This will not override any sType speficications you manually configure. Default is true unless otherwise configured.

:pass_params option

Specifies whether to use paramters associated with the table resource to pre-filter the table data.

:class_name option

ActionTabler likes resourceful routes, so it will guess the model from the controller name. You can override this with the class_name option.

:table_class option

This specifies the html class(es) for your table.

:table_options option

You can specify a hash of additional DataTables options, features and callbacks. This will be added to or override your action_tabler_table_options configuration. See "Datatables fn and m Options" below for more on the special handling of DataTables fn or m options. Please note: you cannot override overriding such options as bProcessing, bServerSide, sAjaxSource, aoColumnDefs, or fnServerParams could have unintended consequences.

See the DataTables web site for more about DataTables Options, Features, and Callbacks.

Datatables fn and m Options

DataTables options which start with m or fn are treated differently, since they can be used to pass context specific Javascript. These options accept three three kinds of value:

  • String: a string which will be evaluated as is;
  • Symbol: the name of a helper method which will be executed with a single argument containing the current column definition hash; or,
  • Proc: a Proc which will passed the current column definition hash.

Running Tests

$ bundle install
$ rspec spec


Copyright (c) 2013 Larry Halff, released under the MIT license