Personal tools
You are here: Home Software Toffee Usage How to integrate Toffee into your Rails application Using the toffee_list helper
Document Actions

Using the toffee_list helper

This How-to applies to: Any version.

A brief guide showing the syntax and some options for customising the results for the toffee_list helper.

New with Toffee is the toffee_list helper. This allows you to stick toffee-generated tables anywhere in your application. Its as simple as putting the following code in one of your views...

<%= toffee_list 'person' %>

The syntax is simple, toffee_list <model_name>, when we put this in app/views/home/index.rhtml - in the example from the previous guide. We get the following...

Picture 9.png


So say you want to customise these results slightly, perhaps you want to show the five oldest people...

<%= toffee_list 'person',
      :list_per_page => 5,
      :list_order => 'date_of_birth' %>

Picture 10.png

You may also want to hide the search bar, the pagination bar, and the options to edit and delete. To do this, edit the code as follows...

<%= toffee_list 'person',
      :list_per_page => 5,
      :list_order => 'date_of_birth',
      :hide_search_bar => true,
      :hide_pagination_bar => true,
      :list_actions => [] %>
Picture 11.png

You can also choose which columns to show, for this example I've created a method called 'age' in person.rb which calculates the persons age based on their date of birth, so just as you would in the model where you would do something like:

@toffee_list_columns = ['first_name','last_name','age','place.name']

When doing it with the helper its as simple as...

<%= toffee_list 'person',
      :list_per_page => 5,
      :list_order => 'date_of_birth',
      :hide_search_bar => true,
      :hide_pagination_bar => true,
      :list_actions => [],
      :list_columns => ['first_name','last_name','age','place.name'],
      :list_headers => ['First Name', 'Last Name', 'Age', 'Place'] %>
And this produces...

Picture 12.png



by dfitzgibbon last modified 2007-04-02 19:01

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: