ruby on rails - Can ActiveScaffold be configured to show the search form before displaying a list? -


When I ask ActiveScaffold to give me a very long list (for example the list of products sold), then query this database Runs to get the first page of data and displays it If there are some links in the list, then it may take some time to execute the query (more than 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 this list.

Is there any way I can tell ActiveScaffold not to display the unfiltered list when the list operation is called? I would like to display this a search form, wait for some criteria to log in, and display only then the filtered list. I found a solution in the controller by defining the conditions_for_collection method in the controller

It's like a hack, but it's easy (3 lines) and it works:

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

How it goes: When you ask for the list, the controller's list method is activated , Is controlled by ActiveScaffold. ActiveScaffold call is conditions_for_collection , and because the action is list ( not update_table ), the returns from the conditions _for_collection method "1 = 2", which Leads to an empty list.

Users can click on the "Search" button, and you can start a search. It calls the update_table operation, again ActiveScaffold call conditions_for_collection , which currently gives no time (no filter), so the entire list is searched.

This is not really beautiful, but it works.


Comments