So Richard White caught up with me a couple of days ago through Technorati and we had a chat about the development of his Ajax Scaffolding as a Rails Plugin. We have agreed to work together on this (which is great) and develop the generator and the plugin in sync (As he also notes in his (kind) comments on the 3.1.3 release of the generator).
Hopefully the first release of the plugin should not to be too far away and will add a little functionality to the existing code.
One of the things I hope we can develop is a nice search interface to the table. I had to do this with the perl Catalyst Framework earlier this year and I think the general approach could work quite well.
The approach I took was to define some (3 in fact) search tags which inherited from the basic html tags. So instead of just a “textfield” I had a “like_textfield”, or a “comparator_textfield”. This allowed me to easily add search functionality for each field in a model. This provides an exceptional comprehensive search system.
To clarify what I mean it is probably easiest to look at the sql mappings the tags produced:
- “comparator_textfield” – used for numerical values, comprises two fields, one a select containing ”<”, ”>” and ”=” and a second for the value. So selecting ”>” and entering “2” in the field would translate to conditions such as “where x < 2”
- “like_textfield” – for full text search, comprises single textfield with a hidden “like” modifier field. So entering “scott rutherford” into the search would give “where x like ‘scott” or x like ‘rutherford’”
- ‘comparator_datefield’ – this was used for searching on dates, so like the numerical case this comprised 2 fields. The first held the modifiers “before”, “on”, “after” and the second drop downs to define the required date. This leads to sql like “where 20060506 < date”, etc.
Rails lends itself very nicely to this approach with the concept of helpers being fundamental to the framework. I feel it would be pretty easy to create helpers for these new search fields and then simply generate a form for a model on the fly as I did (using Richard’s existing helper code) with the scaffold plugin. The interesting bit comes in translating all of this into conditions for ActiveRecord, then storing it for the paging and sorting.
The easiest way to achieve this search persistence I feel is to just use the session object to store the current search, in fact that is the method I used previously and it seemed to work out.
Putting all that together would certainly lead to a radically different search to the “Live” search boxes that are all the rage currently, but my experience of working with tabulated data is that a simple text search is not enough.
At the moment I am beginning to think that this could be a plugin in its own right really and that if it is designed with AjaxScaffold in mind that then the search could potentially be made pluggable. Also of course that would mean you could just generate search forms for standard tables as well as Ajax ones (if that is for some strange reason you didn’t want your tables to look really cool…..).










5 Comments
Scott, take a look at Django’s model CRUD admin interface. This should be the next generation AjaxScaffold. The real problem I have with AS is that it creates a large amount of code in my project for each model. All of this code is templated so there’s no reason why you shouldn’t be able to generate this code at runtime via a plugin instead. Django does just this and additionally supports various types of associations. Your search functionality would also be very helpful.
If you have a public SVN repo for your plugin, I would love to see the code and possibly help you out. I’m just about to start a large new project and it would be extremely helpful to have a plugin, rather than the current generator.
http://www.djangoproject.com/documentation/tutorial2/
Mike, been to have a quick look at that and it seems to be pretty close to the sort of thing I have done / have in mind.
There is no svn repo at the mo while things get a bit settled between the scaffold and the plugin. However, I may stick up a alpha version for people to play with once the api is done cos we can then play with the implmentation without breaking things (including our code at <a href="www.cominded.com">Cominded</a>, which is driving this).
I’m really looking forward to seeing the fruits of your work – installing Ajax Scaffold was a WOW! moment, and then I realised it lacked a search feature
Hi Peter,
Things have been a little slow on the search front recently, Richard and I have been pretty busy with various things. However, we have a first release of the plugin ready which adds some new features (column totals, width, rel_width) so once that is out I will have a think about this again.
Cheers
Scott.
sailing Yacht adriatic. sailing charters croatia.
<a href=http://www.blogoye.org/boatchartercroatia/>charter in croatia</a>