# Using a Number as an Action Name

**URL:** <https://www.ruby-forum.com/t/using-a-number-as-an-action-name/111507>\
**Category:** Rails\
**Created:** [August 8, 2007, 2:43am UTC](https://www.ruby-forum.com/t/using-a-number-as-an-action-name/111507 "2007-08-08T02:43:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [August 8, 2007, 2:43am UTC](https://www.ruby-forum.com/t/using-a-number-as-an-action-name/111507/1 "2007-08-08T02:43:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [August 8, 2007, 3:05am UTC](https://www.ruby-forum.com/t/using-a-number-as-an-action-name/111507/2 "2007-08-08T03:05:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [August 8, 2007, 3:12am UTC](https://www.ruby-forum.com/t/using-a-number-as-an-action-name/111507/3 "2007-08-08T03:12:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [August 8, 2007, 3:18am UTC](https://www.ruby-forum.com/t/using-a-number-as-an-action-name/111507/4 "2007-08-08T03:18:33Z")

</div>

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

def \_100  
end

Cheers.
