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.

2 Responses to “Using routes instead of method_missing in Controllers”

  1. Berin Loritsch Says:

    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.

  2. Berin Loritsch Says:

    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

    def list
      @tag = params[:tag_name]
      @tagged_items = Project.find_tagged_with(
        :any => @tag )
    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.

Leave a Reply

 

Search

A picture of me

I am François Beausoleil, a Ruby on Rails coder. During the day, I work on XLsuite. At night, I am interested many things. Read my biography

Tags

(4) (1) (1) (1) (1) (2) (1) (1) (1) (2) (2) (1) (2) (1) (3) (1) (2) (1) (1) (1) (1) (2) (14) (1) (1) (1) (1) (2) (1) (1) (2) (0) (1) (4) (1) (3) (1) (1) (1) (1) (1) (1) (0) (3) (2) (1) (2) (1) (3) (1) (5) (2) (10) (10) (11) (14) (2) (1) (3) (1) (1) (1) (1) (1) (0) (1) (2) (2) (2) (1) (1) (1) (4) (1) (3) (1) (4) (2) (2) (25) (2) (1) (1) (0) (1) (1) (1) (23) (25) (1) (1) (13) (1) (1) (1) (4) (5) (1) (1) (1) (4) (1) (2) (3) (4) (4) (1) (1) (1) (8) (3) (1) (5) (5) (2) (2) (2) (4) (8) (7) (1) (1) (1) (1) (2) (4) (1) (4) (12) (2) (1) (2) (4) (1) (1) (1) (2) (8) (2) (3) (2) (2) (1) (3) (1) (1)

Links

Projects I work on

Categories

Archives