Search Form

0 views
Skip to first unread message

Worrab

unread,
Nov 30, 2009, 6:48:51 PM11/30/09
to merb
This is probably really straightforward, but I haven't been able to
work out how to build a search into a Merb form and secondly how to
build a form to enter criteria for a SQL search.

For instance, if I have a list of authors, how would a have a field on
the form that users could enter "Br%" with a 'search' button and get
the parameter back to the index ( eg: @authors = Author.all
(:surname.like => 'Br%')

Secondly - and for all I know it's related (!) - if I wanted to list
books and authors, I might have a general search form that had fields
the user could fill in, and build a query with non-blank values. Then
I could use the query as the basis for another form to display the
details.

Any pointers would be greatly valued - thanks.

Jon Hancock

unread,
Dec 1, 2009, 10:47:14 AM12/1/09
to merb
I'm doing something like this now. I first started with the url
representation of a search instead of form contents. Then moved on to
be able to take a form and create a url from its data.

This approach has two benefits for me:
1 - I start knowing that everything is "searchable" through an http/
rest-like query interface.
2 - My merb server doesn't known anything about the form. It has a
param filter and simple custom code to guard the inputs.

For example:
http://mysite.com/books?filter=all;page=2;

This url/query param format may not be rails-ish sexy but it works and
allow me to guard against the filter and page variables so they are
only within "searches" that my app currently allows. You can have
whatever variables you want and the server only pays attention to the
ones the server guards against and ignores the rest.

~ Jon
Reply all
Reply to author
Forward
0 new messages