views:

692

answers:

2

When I ask ActiveScaffold to show me a very long list (for example the list of products sold), it runs the database query to get the first page of data and it displays it. If the list has a few relations, this query might take some time to execute (over a second). Most of the time, I'm not interested in this "unfiltered" list: the first thing I want to do is click on "search" and filter down this list.

Is there any way I could tell ActiveScaffold not to display the unfiltered list when the list action is called? I would like it to simply display the search form, wait for some criteria to be entered, and only then display the filtered list.

A: 

You probably need to override the #index action and provide your own template. It doesn't appear there's any way to tell it to not show that list.

Something like this:

active_scaffold :models do |config|
    config.actions.exclude :index
end

You'll have to then implement your own index method that has it's own template and so on. Hand off back to Active Scaffold's search action. I'm not sure how'd you'd do that, but if you look at the HTML source for the original page you get back it should be pretty clear what action it's linking to that does the search.

Otto
+1  A: 

I found a solution by defining the conditions_for_collection method in the controller. It is kind of a hack, but it's simple (3 lines) and it works:

def conditions_for_collection
  params[:action]=="update_table" ? "" : "1=2"
end

This is how it goes: when you ask for the list, the controller's list method is called, handled by ActiveScaffold. ActiveScaffold calls conditions_for_collection, and since the action is list (not *update_table*), the conditions_for_collection method above returns "1=2", which of course leads to an empty list.

The user can click on the "Search" button, and launch a search. This calls the *update_table* action, again ActiveScaffold calls conditions_for_collection, which this time returns "" (no filter), so the whole list is searched.

It's not really beautiful, but it does the job.

MiniQuark