XAOP Labs

Activescaffold Advanced Search Plugin

A rails plugin to use in combination with activescaffold.

It enhances the built-in search of activescaffold:

  • Search on specific fields
  • Support for different field types: string/text, integer, boolean
  • Different comparison operators :
    • equals
    • contains
    • starts with
    • ends with
    • <
    • >

A simple example to get started :

STEP 1 : Check your Rails version

$ rails --version
Rails 2.3.5

STEP 2 : Generate your Rails app structure

$ rails astest
$ cd astest/

STEP 3 : Create a model

$ script/generate model Book author:string title:string summary:string isbn:string

STEP 4 : Create a controller

$ script/generate controller Books

STEP 5 : Setup database

$ rake db:create
$ rake db:migrate

STEP 6 : Install active scaffold (master for Rails 2.3) and active scaffold search

$ script/plugin install git://github.com/activescaffold/active_scaffold.git
$ script/plugin install git://github.com/xaop/activescaffold_advanced_search

STEP 7 : Define admin.rhtml layout for activescaffold

Taken from http://activescaffold.com/tutorials/getting-started
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
 <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
 <title>Generic ActiveScaffold Layout</title>
 <%= javascript_include_tag :defaults %>

 <%= active_scaffold_includes %>
</head>
<body>

<%= yield  %>

</body>
</html>

STEP 8 : Config controllers

class BooksController < ApplicationController
  layout "admin"
  active_scaffold
end

STEP 9 : Activate active scaffold advanced search

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details

ActiveScaffold.set_defaults do |conf|
  conf.actions.exclude :search
  conf.actions.add :advanced_search
end

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
end

STEP 10 : Start server and check result

$ script/server
Browse to http://localhost:3000/books and play with the interface.

screenshot-advanced-search

Learn more

Advanced Search is managed on Github,