# Default URL and nested resources

**URL:** <https://www.ruby-forum.com/t/default-url-and-nested-resources/143824>\
**Category:** Rails\
**Created:** [July 23, 2008, 3:18am UTC](https://www.ruby-forum.com/t/default-url-and-nested-resources/143824 "2008-07-23T03:18:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [July 23, 2008, 3:18am UTC](https://www.ruby-forum.com/t/default-url-and-nested-resources/143824/1 "2008-07-23T03:18:33Z")

</div>

Say you have resources post and comments, post has many comments. You  
are in CommentsController#index because you asked for  
/posts/8/comments, and you need to generate a link to self with  
additional query string params (in the real applicaction that’s goes  
in the header of a listing to provide column ordering).

Back in the controller/action days \<%= link\_to “current”, :sort\_by =\>  
‘date’ %\> worked, but now that links to /comments?sort\_by=date, so you  
loose the scope over post 8. How would you accomplish that? You cannot  
assume anything because the listing may be scoped in diferent ways or  
not at all, just need to link to self in a clean way.
