Using routes instead of method_missing in Controllers
February 27th, 2006
Over on Software Development Budoka, Berin Loritsch talks about supporting The Rel-Tag Microformat in Rails. Unfortunately, he uses a very obscure approach.
Here is his code: Unfortunately, that is very unclear. Much better to use routes to do the same thing:In my mind, that seems to be the easiest way to do the job.
October 12th, 2007 at 10:25 PM
You know, I tend to not want to mess with routes too much. However, you are right in that you have outlined a cleaner approach.
I just remember some code from a demo which created a “playback” object. I.e. something that recorded actions on an object so that you could play them back on something else. That’s what came to mind.
I am a Ruby Nuby so I am always open to learning how to do things better.
October 12th, 2007 at 10:25 PM
I did the repairs, and I made it even a little more clean than what you presented. Check this out:
ActionController::Routing::Routes.draw do |map| map.connect ‘tags/:tag_name’, :controller => ‘tags’, :action => ‘list’ end
class TagsController < ApplicationController layout ‘site’ end
The only reason I had to have the “render ‘tags/list’” line in the method_missing call is because I couldn’t take advantage of the default behavior for rhtml selection. By using routes, I could.