# Names and nested routes?!?

**URL:** <https://www.ruby-forum.com/t/names-and-nested-routes/155131>\
**Category:** Rails\
**Created:** [December 8, 2008, 1:55pm UTC](https://www.ruby-forum.com/t/names-and-nested-routes/155131 "2008-12-08T13:55:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [December 8, 2008, 1:55pm UTC](https://www.ruby-forum.com/t/names-and-nested-routes/155131/1 "2008-12-08T13:55:56Z")

</div>

Hi Guys,

I have the following route to show the articles for a selected service  
in my application.

[http://localhost:3000/services/4/articles](http://localhost:3000/services/4/articles)

I want to be able to have a route to the service name rather than the  
route such as the following.

[http://localhost:3000/services/clothes/articles](http://localhost:3000/services/clothes/articles)

I thought something like the following in the routes.rb file would be  
the way forward?

map.connect ‘clothes/’, :controller =\> ‘articles’, :action =\> “index”,  
:service\_id =\> ‘4’

Many thanks in advance

Dave

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [December 8, 2008, 2:38pm UTC](https://www.ruby-forum.com/t/names-and-nested-routes/155131/2 "2008-12-08T14:38:13Z")

</div>

On Mon, Dec 8, 2008 at 1:55 PM, Dave S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [http://localhost:3000/services/clothes/articles](http://localhost:3000/services/clothes/articles)

Assuming that the attribute of the Service is called name,  
you should define this in your Service model:

def to\_param  
name  
end

for more info, look at this post:

> **[Best Online Casino in Australia | Top Licensed Casinos for Gamblers](https://toponlinecasinoaustralia.com)**
>
> Best Online Casino in Australia with licensed games only. Play blackjack, roulette, poker and other top-notch casino games. Enjoy gambling 24/7.

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [December 8, 2008, 4:08pm UTC](https://www.ruby-forum.com/t/names-and-nested-routes/155131/3 "2008-12-08T16:08:56Z")

</div>

Franz S. wrote:

> On Mon, Dec 8, 2008 at 1:55 PM, Dave S.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > [http://localhost:3000/services/clothes/articles](http://localhost:3000/services/clothes/articles)
> 
> Assuming that the attribute of the Service is called name,  
> you should define this in your Service model:
> 
> def to\_param  
> name  
> end
> 
> for more info, look at this post:
> 
> [Best Online Casino in Australia | Top Licensed Casinos for Gamblers](http://www.jroller.com/obie/entry/seo_optimization_of_urls_in)

I used the following code in the end, as I have a field title in the  
table.

def to\_param  
id.to\_s+‘-’+title.downcase.gsub(’ ', ‘-’)  
end

However it puts the address with the ID at the beginning;

[http://localhost:3000/services/1-horse-&-groom/articles](http://localhost:3000/services/1-horse-&-groom/articles)

Is there a way I can remove this from the address to tidy it up a bit?
