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.
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.