# Generically mapping URLs with hyphens to actions

**URL:** <https://www.ruby-forum.com/t/generically-mapping-urls-with-hyphens-to-actions/52823>\
**Category:** Rails\
**Created:** [December 7, 2005, 10:18pm UTC](https://www.ruby-forum.com/t/generically-mapping-urls-with-hyphens-to-actions/52823 "2005-12-07T22:18:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [December 7, 2005, 10:18pm UTC](https://www.ruby-forum.com/t/generically-mapping-urls-with-hyphens-to-actions/52823/1 "2005-12-07T22:18:05Z")

</div>

Has anybody figured out a way to generically map URLs with hyphens to  
their corresponding  
underscore-named actions? e.g.

members/submit-item → members#submit\_item

thanks  
csn

* * *

Yahoo! DSL ? Something to write home about.  
Just $16.99/mo. or less.  
[dsl.yahoo.com](http://dsl.yahoo.com)

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [December 9, 2005, 4:05pm UTC](https://www.ruby-forum.com/t/generically-mapping-urls-with-hyphens-to-actions/52823/2 "2005-12-09T16:05:29Z")

</div>

cool\_screen\_name90001 wrote:

> Has anybody figured out a way to generically map URLs with hyphens to  
> their corresponding  
> underscore-named actions? e.g.
> 
> members/submit-item -\> members#submit\_item
> 
> thanks  
> csn

Don’t count on it - I think those #'s would be seen as browser entities  
(they’re used for putting links to a specified place on the page), so I  
don’t think they’d get sent to the server.

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [December 9, 2005, 5:05pm UTC](https://www.ruby-forum.com/t/generically-mapping-urls-with-hyphens-to-actions/52823/3 "2005-12-09T17:05:45Z")

</div>

On 12/9/05, Thomas [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> cool\_screen\_name90001 wrote:
> 
> > Has anybody figured out a way to generically map URLs with hyphens to  
> > their corresponding  
> > underscore-named actions? e.g.
> > 
> > members/submit-item → members#submit\_item
> > 
> > thanks  
> > csn

Rails provides the members/submit\_item → members#submit\_item mapping  
for free. Is there something wrong with underscores?

–  
rick  
[http://techno-weenie.net](http://techno-weenie.net)

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [December 9, 2005, 6:31pm UTC](https://www.ruby-forum.com/t/generically-mapping-urls-with-hyphens-to-actions/52823/4 "2005-12-09T18:31:35Z")

</div>

On 9-Dec-05, at 8:00 AM, Rick O. wrote:

> > > Has anybody figured out a way to generically map URLs with  
> > > hyphens to  
> > > their corresponding  
> > > underscore-named actions? e.g.
> > > 
> > > members/submit-item -\> members#submit\_item
> 
> Rails provides the members/submit\_item -\> members#submit\_item mapping  
> for free. Is there something wrong with underscores?

I have heard of two cases where a hyphen is better than an underscore  
in URLs:

In HTML, when a URL is used as the text in an anchor tag, the default  
styling  
in most browsers is to underline the text. In this case the underscore  
will blend in with the underline, and some users will mistake it for  
a space  
when writing the URL down and/or later typing it in.

When indexing a page Google considers the hyphen to be word divider,  
while an  
underscore is not. So /submit-item will be indexed as “submit item”,  
where as submit\_item will be “submititem”. GoogleGuy (a Google  
employee)  
has recommended hyphens instead of underscores in URLs if you want the  
word boundaries to be recognized.

If there is no preference either way, then I’d suggest using hyphens  
instead of underscores in URLs. Its too bad that Rails doesn’t have any  
native support to remap them to actions though.

–

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![cool\_screen\_name900](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@cool\_screen\_name900](https://www.ruby-forum.com/u/cool_screen_name900)\
**Post date:** [December 9, 2005, 7:18pm UTC](https://www.ruby-forum.com/t/generically-mapping-urls-with-hyphens-to-actions/52823/5 "2005-12-09T19:18:34Z")

</div>

CSN wrote:

> Has anybody figured out a way to generically map URLs with hyphens to their corresponding  
> underscore-named actions? e.g.
> 
> members/submit-item → members#submit\_item

This may not be exactly what you want, but it may help.

[http://blog.teksol.info/articles/2005/10/25/actions-with-dashes](http://blog.teksol.info/articles/2005/10/25/actions-with-dashes)
