# Changing the URL if in nested resources

**URL:** <https://www.ruby-forum.com/t/changing-the-url-if-in-nested-resources/120933>\
**Category:** Rails\
**Created:** [November 21, 2007, 9:46pm UTC](https://www.ruby-forum.com/t/changing-the-url-if-in-nested-resources/120933 "2007-11-21T21:46:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rich\_VSSSSzquez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e99b99/32.png) [@Rich\_VSSSSzquez](https://www.ruby-forum.com/u/Rich_VSSSSzquez)\
**Post date:** [November 21, 2007, 9:46pm UTC](https://www.ruby-forum.com/t/changing-the-url-if-in-nested-resources/120933/1 "2007-11-21T21:46:38Z")

</div>

I have a nested restful resource working

map.resources :works do |work|  
work.resources :work\_sections  
end

producing a url like:  
/works/2/work\_sections/1

I’d like to do two things with the URL, but am not sure where to start.

1. I’d like to restrict the work\_section from displaying if the work\_id  
isn’t legit.  
Right now /works/2/work\_sections/1 will pull up work\_section\_id 1 even  
if it  
is associated with work\_id 1 (contrary to the url)

2. Make it so that the work\_section number in the URL is the :position  
(as  
opposed to :id) for the work\_section which is an acts\_as\_list child of  
work.  
I want to avoid ending up with a url like:  
/works/223/work\_sections/12838

I’m pretty sure accomplishing #2 will include my want for #1.

Is there an example or particular concept I need to look to research how  
to  
do this type of routing?

## –

Rich VÃ¡zquez, CISSP, CISA

---

<div class="post-metadata">

**Author:** ![Rich\_VSSSSzquez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e99b99/32.png) [@Rich\_VSSSSzquez](https://www.ruby-forum.com/u/Rich_VSSSSzquez)\
**Post date:** [December 21, 2007, 10:58am UTC](https://www.ruby-forum.com/t/changing-the-url-if-in-nested-resources/120933/2 "2007-12-21T10:58:21Z")

</div>

Check that in your controller code, make sure you use  
work\_object.work\_sections.find()
