# How to use the fixed part for the method url\_for?

**URL:** <https://www.ruby-forum.com/t/how-to-use-the-fixed-part-for-the-method-url-for/159160>\
**Category:** Rails\
**Created:** [February 1, 2009, 4:55pm UTC](https://www.ruby-forum.com/t/how-to-use-the-fixed-part-for-the-method-url-for/159160 "2009-02-01T16:55:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [February 1, 2009, 4:55pm UTC](https://www.ruby-forum.com/t/how-to-use-the-fixed-part-for-the-method-url-for/159160/1 "2009-02-01T16:55:44Z")

</div>

If i have the following routes:  
###############  
map.connect “blog/:controller/:action/:id”  
map.connect “product/:controller/:action/:id”  
##############  
when use url\_for or some else to generate the url,how to make sure  
that url\_for use the first route to generate the url “blog/articles/  
show/1” ?  
what to add to the  
url\_for(:controller=\>“articles”,:action=\>“show”,:id=\>“1”) ?  
like this?  
url\_for  
(:controller=\>“articles”,:action=\>“show”,:id=\>“1”,:anchor=\>“blog”)

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [February 1, 2009, 5:05pm UTC](https://www.ruby-forum.com/t/how-to-use-the-fixed-part-for-the-method-url-for/159160/2 "2009-02-01T17:05:48Z")

</div>

Hi,

On Feb 1, 4:54 pm, daociyiyou [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> like this?  
> url\_for  
> (:controller=\>“articles”,:action=\>“show”,:id=\>“1”,:anchor=\>“blog”)

Why not use this route:  
map.resources :articles, :as =\> ‘blog’

Then you can call article\_path(@article)  
For all routes that map.resources creates do a ‘rake routes’ on the  
console.

ciao, tom

–  
Thomas R. “TomK32” Koll \<\> [http://ananasblau.com](http://ananasblau.com)  
just a geek trying to change the world  
[TomK32 (Thomas R. Koll) · GitHub](http://github.com/TomK32)

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [February 1, 2009, 6:02pm UTC](https://www.ruby-forum.com/t/how-to-use-the-fixed-part-for-the-method-url-for/159160/3 "2009-02-01T18:02:46Z")

</div>

But how to do for url\_for method to generate “blog/articles/ show/1”?
