Using a Number as an Action Name

I need/want to create actions using a number. For example:

class ClickController < ApplicationController

  caches_page(:index, :100, :200)

  def index
  end

  def 100
  end

  def 200
  end
end

I keep running into problems with the numbers. Unexpected integer,
etc. Single-quoting them in the cashes_page command got rid of the
errors on that line, but how do I define an action with a number as
its name?

Thanks.

hi,

  def 100
  end

errors on that line, but how do I define an action with a number as
its name?
  

I'd say you cannot. A method name should start with a non-numeric character. Anyway you could define a route for each of the actions in your routes.rb

being verbose, you could define the actions in the controller as action_100, for example, and just make the route to 'Clicks/100' go to :action=>'action_100'

but if you are going to have a bunch of actions like those, i think this would do better

map.connect ':controller/:action_number/',:conditions=>{:action_number=>/\d/}, :action=>'numeric_dispatch'

that way, if in any of your controllers you receive an action with only digits, it will call "numeric_dispatch" on that controller passing the :action_number param.

just be sure you define it before the default routes, so it gets higher priority

regards,

javier ramírez

hi again

i realized i had a small mistake.. just use the following map.connect

map.connect ':controller/:action_number/',:requirements=>{:action_number=>/\d+/}, :action=>'numeric_dispatch'

cheers,

javier ramirez

Turns out by prefixing the def name with an underscore works:

def _100
end

Cheers.