If controller doesn't exist: search database for its name

I’ll use my recipe example again.
It would be nice if I could have my routes (I think) set up so that if
somebody enters a a controller that doesn’t exist a database search
runs and looks for the controller name as one of the categories (for
example the user enters http://www.com/italian). This is an existing
category in the database so it would likely then redirect to
www.com/categories/italian (and from there the categories controller
would handle things).

Is this possible without violating any “rules”?

On 11 May 2010 21:03, sso [email protected] wrote:

if somebody enters a a controller that doesn’t exist a database search
runs and looks for the controller name

Is this possible without violating any “rules”?

You would probably be able to do something by catching 404 errors in
your application controller and then punting them off to a method that
tries to guess what the user meant. Google for “Rails 404” for a few
methods to try.

Michael P. wrote:

On 11 May 2010 21:03, sso [email protected] wrote:

if somebody enters a a controller that doesn’t exist a database search
runs and looks for the controller name

Is this possible without violating any “rules”?

You would probably be able to do something by catching 404 errors in
your application controller and then punting them off to a method that
tries to guess what the user meant. Google for “Rails 404” for a few
methods to try.

Actually, no 404 catching is necessary. All you need is a catchall
route that sends ‘/:category’ off to a search action.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On Tue, May 11, 2010 at 3:03 PM, sso [email protected] wrote:

You can override method_missing. We used that approach at my last gig
to
grab userr-created content from a SharePoint site.

HTH,
Bill