# Rewrite hyphen to underscore

**URL:** <https://www.ruby-forum.com/t/rewrite-hyphen-to-underscore/47949>\
**Category:** Rails\
**Created:** [November 15, 2005, 11:01am UTC](https://www.ruby-forum.com/t/rewrite-hyphen-to-underscore/47949 "2005-11-15T11:01:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan.kubb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@dan.kubb](https://www.ruby-forum.com/u/dan.kubb)\
**Post date:** [November 15, 2005, 11:01am UTC](https://www.ruby-forum.com/t/rewrite-hyphen-to-underscore/47949/1 "2005-11-15T11:01:44Z")

</div>

I have a Routes question. Say I have the following routes.rb  
configuration:

ActionController::Routing::Routes.draw do |map|  
map.connect ‘:controller/:action’, :action =\>  
‘index’, :requirements =\> { :action =\> /(?:a-z\*)/ }  
map.connect ‘:controller/:id’, :action =\>  
‘show’, :requirements =\> { :id =\> /\d+/ }  
map.connect ‘:controller/:id/:action’  
end

Notice that I want to use hyphens in the action name? Is there  
any way to “rewrite” this inside Rails so that the hyphen becomes  
an underscore?

So for example I want:

/person/list-all

to map to:

:controller =\> ‘person’, :action =\> ‘list\_all’

I prefer to use a hyphens in my URIs because in an underlined link  
the underscore character can sometimes be mistaken for a space.

Also, for the third connect call, do I have to specify the requirements  
for the :action and :id that were specified earlier if I want the same  
requirements to continue to apply?

–

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![dan.kubb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@dan.kubb](https://www.ruby-forum.com/u/dan.kubb)\
**Post date:** [November 15, 2005, 2:49pm UTC](https://www.ruby-forum.com/t/rewrite-hyphen-to-underscore/47949/2 "2005-11-15T14:49:34Z")

</div>

Hello Dan !

2005/11/15, Dan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Notice that I want to use hyphens in the action name? Is there  
> any way to “rewrite” this inside Rails so that the hyphen becomes  
> an underscore?

I blogged about that about a month ago:  
[http://blog.teksol.info/articles/2005/10/25/actions-with-dashes](http://blog.teksol.info/articles/2005/10/25/actions-with-dashes)

Hope that helps !
