# Getting named parameters from routes

**URL:** <https://www.ruby-forum.com/t/getting-named-parameters-from-routes/104685>\
**Category:** Rails\
**Created:** [May 21, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/getting-named-parameters-from-routes/104685 "2007-05-21T15:28:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Stott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@Jonathan\_Stott](https://www.ruby-forum.com/u/Jonathan_Stott)\
**Post date:** [May 21, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/getting-named-parameters-from-routes/104685/1 "2007-05-21T15:28:02Z")

</div>

I’m trying nested resources for a RESTful rails application.

So, I set my routes up like so:

map.resources :articles do |article|  
article.resources :comments  
end

and when I “GET /articles/1”, the 1 is assigned to params[:id]  
But when I “GET /articles/1/comments/2”, the 1 is :article\_id, and the  
2 becomes :id. Which works just fine. Except that if I want  
before\_filters to find the article and the comments, I need to have an  
almost identical, but not quite, find\_article function in the articles  
and the comments function. One finds the article with param id, one  
with param article\_id.

Is there some way I could change things so that everything was known  
by the ‘full name’ rather than the final parameter being shortened?

Jon

---

<div class="post-metadata">

**Author:** ![Jonathan\_Stott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@Jonathan\_Stott](https://www.ruby-forum.com/u/Jonathan_Stott)\
**Post date:** [May 21, 2007, 5:30pm UTC](https://www.ruby-forum.com/t/getting-named-parameters-from-routes/104685/2 "2007-05-21T17:30:24Z")

</div>

I have not used this yet, but I would look at the source for  
map.resources and see if there are options for controlling the name  
used for the id. It clearly generates different values for article  
based on whether there is a block present. You could always assign a  
block to the comments map resources with nothing in it and see if that  
forced it to comment\_id.

Also, one of the people I talked with at RailsConf indicated that  
nested resources were broken in edge. Are you using edge or 1.2?

Michael
