# Changing the path for map.resources

**URL:** <https://www.ruby-forum.com/t/changing-the-path-for-map-resources/175610>\
**Category:** Rails\
**Created:** [September 16, 2009, 3:16pm UTC](https://www.ruby-forum.com/t/changing-the-path-for-map-resources/175610 "2009-09-16T15:16:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve\_bell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@steve\_bell](https://www.ruby-forum.com/u/steve_bell)\
**Post date:** [September 16, 2009, 3:16pm UTC](https://www.ruby-forum.com/t/changing-the-path-for-map-resources/175610/1 "2009-09-16T15:16:41Z")

</div>

Hi there, just starting to get my head around routes but have a  
problem that I can’t google my way out of. I have a restful resource  
that’s mapped as:

map.resources :terms

which gives me localhost/terms, however I want it to be localhost/  
buzzwords instead.

I tried using path\_prefix but this just added the prefix before /  
terms. I guess I really want a path\_replace kind of thing…

Refactoring the code would be a real pain. Is there any way to do this  
in the routes.rb file?

Thanks,

Steve

---

<div class="post-metadata">

**Author:** ![steve\_bell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@steve\_bell](https://www.ruby-forum.com/u/steve_bell)\
**Post date:** [September 16, 2009, 3:17pm UTC](https://www.ruby-forum.com/t/changing-the-path-for-map-resources/175610/2 "2009-09-16T15:17:16Z")

</div>

Hi –

On Wed, 16 Sep 2009, steve bell wrote:

> I tried using path\_prefix but this just added the prefix before /  
> terms. I guess I really want a path\_replace kind of thing…
> 
> Refactoring the code would be a real pain. Is there any way to do this  
> in the routes.rb file?

You need to invert the logic:

map.resources :buzzwords, :controller =\> “terms”

David

–  
David A. Black, Director  
Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))  
Ruby/Rails training, consulting, mentoring, code review  
Book: The Well-Grounded Rubyist ([The Well-Grounded Rubyist](http://www.manning.com/black2))

---

<div class="post-metadata">

**Author:** ![steve\_bell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@steve\_bell](https://www.ruby-forum.com/u/steve_bell)\
**Post date:** [September 16, 2009, 3:19pm UTC](https://www.ruby-forum.com/t/changing-the-path-for-map-resources/175610/3 "2009-09-16T15:19:02Z")

</div>

Am 16.09.2009 um 15:03 schrieb David A. Black:

> > which gives me localhost/terms, however I want it to be localhost/
> 
> map.resources :buzzwords, :controller =\> “terms”

Or the other way round:

map.resources :terms, :as =\> ‘buzzwords’

See the other options for resources here  
[http://apidock.com/rails/ActionController/Resources/resources](http://apidock.com/rails/ActionController/Resources/resources)

Regards,

Felix

---

<div class="post-metadata">

**Author:** ![steve\_bell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@steve\_bell](https://www.ruby-forum.com/u/steve_bell)\
**Post date:** [September 16, 2009, 6:18pm UTC](https://www.ruby-forum.com/t/changing-the-path-for-map-resources/175610/4 "2009-09-16T18:18:12Z")

</div>

many thanks guys, I ended up using the , :as =\> and it did the trick.

thanks for the link felix - it’s now in my bookmarks!

Steve

---

<div class="post-metadata">

**Author:** ![steve\_bell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@steve\_bell](https://www.ruby-forum.com/u/steve_bell)\
**Post date:** [September 24, 2009, 3:46pm UTC](https://www.ruby-forum.com/t/changing-the-path-for-map-resources/175610/5 "2009-09-24T15:46:31Z")

</div>

Hi –

On Wed, 16 Sep 2009, Felix SchÃ¤fer wrote:

> > > that’s mapped as:  
> > > this  
> > > in the routes.rb file?
> > 
> > You need to invert the logic:
> > 
> > map.resources :buzzwords, :controller =\> “terms”
> 
> Or the other way round:
> 
> map.resources :terms, :as =\> ‘buzzwords’

True, though I guess I like being able to see the name up front. It  
seems like a more “top down” way: the resource mapping is buzzwords,  
the implementation involves the terms controller, etc.

(Unless there’s some subtle difference that I’m overlooking in the  
effect they have.)

David

–  
David A. Black, Director  
Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))  
Ruby/Rails training, consulting, mentoring, code review  
Book: The Well-Grounded Rubyist ([The Well-Grounded Rubyist](http://www.manning.com/black2))
