# How to create routes for user

**URL:** <https://www.ruby-forum.com/t/how-to-create-routes-for-user/203145>\
**Category:** Rails\
**Created:** [February 14, 2011, 7:04am UTC](https://www.ruby-forum.com/t/how-to-create-routes-for-user/203145 "2011-02-14T07:04:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 14, 2011, 7:04am UTC](https://www.ruby-forum.com/t/how-to-create-routes-for-user/203145/1 "2011-02-14T07:04:17Z")

</div>

I have a user. They have could have many products

The typical link in rails would be  
[www.somesite.com/controller/action/id](http://www.somesite.com/controller/action/id)

what I want is it to look like

[www.somesite.com/user\_name/product\_name](http://www.somesite.com/user_name/product_name)

How can I do this using routes.rb

Thank

Mitch

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [February 14, 2011, 9:56am UTC](https://www.ruby-forum.com/t/how-to-create-routes-for-user/203145/2 "2011-02-14T09:56:00Z")

</div>

you can use

match “/:user\_name/:product\_name” =\> “products#show”

but be sure to place this at the bottom of your routes file so it will  
match  
if not any other routes match.  
one big problem i’m seeing with this approach is if a user’s name is the  
same as one of your controllers.  
so you have to consider that.

On Mon, Feb 14, 2011 at 2:04 PM, Mitchell G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> “Ruby on Rails: Talk” group.  
> To post to this group, send email to [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid).  
> To unsubscribe from this group, send email to  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid).  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [February 14, 2011, 2:15pm UTC](https://www.ruby-forum.com/t/how-to-create-routes-for-user/203145/3 "2011-02-14T14:15:07Z")

</div>

On Feb 14, 2011, at 1:04 AM, Mitchell G. wrote:

> I have a user. They have could have many products
> 
> The typical link in rails would be  
> [www.somesite.com/controller/action/id](http://www.somesite.com/controller/action/id)
> 
> what I want is it to look like
> 
> [www.somesite.com/user\_name/product\_name](http://www.somesite.com/user_name/product_name)
> 
> How can I do this using routes.rb

You might want to look at friendly\_id, that’s right up its alley.

Walter
