Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Lists with a dash of ferret
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
tasks
MIT-LICENSE
README.rdoc
Rakefile
init.rb

README.rdoc

ListingFu

ListingFu is a compact DSL for defining and searching in lists of content in your Rails app, it uses ferret as backend to work its fast magic.

Model

We define our different filters we want to use in our app inside the model:

class Person < ActiveRecord::Base
  has_many :memberships
  has_many :groups, :through => :memberships

  has_one :account

  listing_filter :name => :name, :age => :age, :account_name => lambda { account.name }, :groups => lambda { groups.join(' ') }
end

View

In our view we can now use our defined filters to filter the listing to find the content we want:

<% filters(@people) do |filters| %>
  <%= filters.text_filter :name %>
  <%= filters.options_filter :age, [12, 13, 14] %>
<% end %>

This is the actual listing code that renders a table with clickable headers to do the sorting:

<% listing(@people) do |listing| %>
  <%= listing.column :name %>

  <% listing.column :age do |person| %>
    <%= "My age is #{person.age}" %>
  <% end %>

  <% listing.actions do |person| %>
    <td><%= link_to 'Show', person %></td>
    <td><%= link_to 'Edit', edit_person_path(person) %></td>
    <td><%= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete %></td>
  <% end %>
<% end %>

Controller

Then in our controller we just use the listing method with the parameters from the view

@people = Person.listing params, :per_page => 50

Copyright © 2009 Joakim Ekberg, released under the MIT license

Something went wrong with that request. Please try again.