# Routing problem

**URL:** <https://www.ruby-forum.com/t/routing-problem/162478>\
**Category:** Rails\
**Created:** [March 10, 2009, 10:05am UTC](https://www.ruby-forum.com/t/routing-problem/162478 "2009-03-10T10:05:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![makarakao](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@makarakao](https://www.ruby-forum.com/u/makarakao)\
**Post date:** [March 10, 2009, 10:05am UTC](https://www.ruby-forum.com/t/routing-problem/162478/1 "2009-03-10T10:05:56Z")

</div>

Hi all,

I want the url something like this:

[http://localhost:3000/profile/anyusername](http://localhost:3000/profile/anyusername)

This will access the controller: profile and the action: view and the  
value “anyusername” is the :username parameter.  
So I wrote in my route file something like this

map.connect ‘profile/:username’, :controller =\>  
‘profile’, :action=\>‘view’

But what I want more is that except for the value “index”,“edit”, and  
“update”. When the user type the url:

[http://localhost:3000/profile/index](http://localhost:3000/profile/index), it will access controller:  
profile and action: index. For “edit” and “update” are in the same  
process.

So my finally route is:

map.connect ‘profile/index’, :controller =\>  
‘profile’, :action=\>‘index’  
map.connect ‘profile/edit’, :controller =\> ‘profile’, :action=\>‘edit’  
map.connect ‘profile/update’, :controller =\>  
‘profile’, :action=\>‘update’  
map.connect ‘profile/:username’, :controller =\>  
‘profile’, :action=\>‘view’

And they are working fine. But I think it’s too long.  
Are there any ways that is shorter than the above.

Thanks in advance,

Mako

---

<div class="post-metadata">

**Author:** ![makarakao](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@makarakao](https://www.ruby-forum.com/u/makarakao)\
**Post date:** [March 11, 2009, 12:52pm UTC](https://www.ruby-forum.com/t/routing-problem/162478/2 "2009-03-11T12:52:30Z")

</div>

On Tue, Mar 10, 2009 at 9:47 AM, Mako [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So my finally route is:  
> Are there any ways that is shorter than the above.
> 
> Thanks in advance,
> 
> Mako
> 
> >

What about:  
map.connect ‘profile/:username’, :controller =\> ‘profile’, :action =\>  
‘view’  
map.connect ‘profile/:action’, :controller =\> ‘profile’

Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)  
[http://www.linkedin.com/in/andrewtimberlake](http://www.linkedin.com/in/andrewtimberlake)

“I have never let my schooling interfere with my education” - Mark Twain

---

<div class="post-metadata">

**Author:** ![makarakao](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@makarakao](https://www.ruby-forum.com/u/makarakao)\
**Post date:** [March 11, 2009, 1:22pm UTC](https://www.ruby-forum.com/t/routing-problem/162478/3 "2009-03-11T13:22:27Z")

</div>

Andrew T. wrote:

> > So my finally route is:  
> > Are there any ways that is shorter than the above.  
> > Andrew T.  
> > [http://ramblingsonrails.com](http://ramblingsonrails.com)  
> > [http://www.linkedin.com/in/andrewtimberlake](http://www.linkedin.com/in/andrewtimberlake)
> 
> “I have never let my schooling interfere with my education” - Mark Twain

map.connect ‘/profile/:action’, :controller =\> ‘profile’, :requirements  
=\> {:action =\> /(edit|update|new|index)/ }  
map.connect ‘/profile/:username’, :controller =\> ‘profile’, :action =\>  
‘view’

## tom

===============================================================================  
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

# [www.meinlschmidt.com](http://www.meinlschmidt.com) www.maxwellrender.cz www.lightgems.cz
