Skip to content

DataTables on Ruby on Rails

Below is short tutorial on how to use the famous DataTables jQuery plugin. You can find additional information on datatables.net

Prerequisites

This tutorial has been successfully tested on below environments but should work

  • Rails 2, 3 and greater
  • Ruby 1.8.7 and greater
  • jQuery 1.9.0 and greater
  • DataTables 1.9.4

Users on rails 2 and less are required to download  jQuery 1.9.0 or greater (preferably the minified version) on jquey.com and place the file under the public folder :

rails 2 : public/javascripts/

rails 3 and greater : assests/javascripts/

Installation

(1) Download the DataTables jQuery plugin from http://www.datatables.net/

(2) Extract the content on your desired location

(3) Copy all files in media into your public folder

==files to copy
media/images/*
media/js/*
media/css/*

==rails public folder
rails 2 :
public/javascripts
public/images
public/stylesheets

rails 3+ :
assets/javascripts
assets/images
assets/stylesheets

(4) Copy the following files in your corresponding rails public folder

==files to copy
extra/TableTools/media/js/TableTools.min.js
extra/TableTools/media/js/ZeroClipboard
extra/TableTools/media/css/TableTools_JUI.css
extra/TableTools/media/css/TableTools.css
extra/TableTools/media/sw/copy_csv_xls_pdf.swf (this file goes into the public folder on both rails 2 & 3+)

==public folder
rails 2 :
public/javascripts
public/images
public/stylesheets

rails 3+:
assets/javascripts
assets/images
assets/stylesheets

(5) Set your layout :

<%= stylesheet_link_tag "jquery.dataTables", "TableTools", "TableTools_JUI"%>
<%= javascript_include_tag "jquery", "jquery.dataTables","TableTools.min" %>

(6) Set your controller & view

# app/controllers/list_controller.rb
def index
  @list = Product.find(:all)
  respond_to do |format|
    format.html {render: @list }
  end
end

# app/views/list/index.html.erb

<script>

  $(document).ready(function() {
    $('#list').dataTable({
      "sDom": 'T<"clear">lfrtip',
      "oTableTools": {
      "sSwfPath": "copy_csv_xls_pdf.swf"
      }
    });
  } );
</script>

<h3>List</h3>
<table id="list">
  <thead>
    <tr>
      <th>Col 1</th>
      <th>Col 2</th>
    </tr>
  </thead>
  <tbody>
    <% @list.each do |i| %>
      <tr>
        <td><%= i.col1 %></td>
        <td><%= i.col2 %></td>
      </tr>
    <% end %>
  </tbody>
</table>
<br />

Install Kannel WAP/SMS Gateway on Ubuntu

Kannel is a compact and very powerful open source WAP and SMS gateway, used widely across the globe both for serving trillions of short messages (SMS), WAP Push service indications and mobile internet connectivity.
If you intend to play around with SMS’es, build your own SMS application, this tool is perfect for you!!!
Now, for newbies who would wish to use this extraordinary piece of work, you might find yourself stuck trying to install it. The steps are pretty straight forward but not self explanatory in the Kannel user guide (http://kannel.org/download/kannel-userguide-snapshot/userguide.html), which you will definitely need after you have successfully installed it.

This short guide is based on Ubuntu Linux (from 8.04 to 10.04) but should work on other Linux distros (Fedora, CentOS, SUSE, etc)

Pretty much of the work here will be performed via command line, so i would suggest you to fire up your beloved Terminal 🙂

Step 1 : Download Kannel sources (http://kannel.org/download.shtml)
RPM and Debian packages are available but i will recommend to install it from sources.
Download the most stable release 1.4.3
#Go to a specific location (i am using /usr/local/src, but yours could be different, just make sure it exists)
$ cd /usr/local/src
#Download sources
$ wget http://kannel.org/download/1.4.3/gateway-1.4.3.tar.gz
#Extract tarball
$ tar -xzvf gateway-1.4.3.tar.gz
$ cd gateway-1.4.3/

Step 2 : Install required libraries
Kannel requires the following software environment:
– C compiler and libraries for ANSI C, with normal Unix extensions such as BSD sockets and relate tools. (GNU’s GCC tool-chain is recommended)
– The Gnome XML library (known as gnome-xml and libxml), version 2.2.5 or newer.
– GNU Make
– An implementation of POSIX threads
– GNU Bison 1.28
– DocBook processing tools: DocBook style-sheets, jade, jadetex, etc;
– GNU autoconf, if you want to modify the configuration script

You might wonder, “How do i get all this stuff installed??”
Relax, this is how you should proceed :
#C compiler and libraries for ANSI C
$ sudo apt-get install build-essential
#The Gnome XML library
$ sudo apt-get install libxml2 libxml2-dev
#Optional : if you wish to use MySQL with your Kannel installation (details can be found in the user guide)
$ sudo apt-get install libmysqlclient15-dev

Step 3 : Compile Kannel sources
Depending on how you would wish to compile it, refer to the user guide to see other options (Chapter 2 : Installing the Gateway, section : Compiling the gateway)
The default compile is :
$ ./configure
But i recommend :
$ ./configure –prefix=/usr/local/kannel –enable-start-stop-daemon
–prefix defines where your current installation will be located (my current location is /usr/local/kannel but you can use a different one as long as it exists)
–enable-start-stop-daemon compiles a start/stop daemon program to run kannel
If you wish to enable MySQL :
$ ./configure –prefix=/usr/local/kannel –enable-start-stop-daemon –with-mysql

Step 4 : Install compiled sources
$ make
$ sudo make install

That’s it, now real stuff can start!!!

But before that, I would suggest you to read “Chapter 3 : Using the gateway” in the user guide

If you get stuck or need help on how to proceed, email me on mutesach@gmail.com

Happy hacking !!! 🙂