# How to automatically set params based on passed object when generating a route?

**URL:** <https://www.ruby-forum.com/t/how-to-automatically-set-params-based-on-passed-object-when-generating-a-route/187406>\
**Category:** Rails\
**Created:** [April 22, 2010, 5:50pm UTC](https://www.ruby-forum.com/t/how-to-automatically-set-params-based-on-passed-object-when-generating-a-route/187406 "2010-04-22T17:50:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [April 22, 2010, 5:50pm UTC](https://www.ruby-forum.com/t/how-to-automatically-set-params-based-on-passed-object-when-generating-a-route/187406/1 "2010-04-22T17:50:29Z")

</div>

Hi,

having i.e. a post model that has many categories - is it possible for  
member routes like i.e. post\_path(post) to generate path like “/  
posts/:post\_category\_name/:post\_id” without manually passing the  
category param? Does anyone know if there’s a gem or if I can simply  
override the post\_url method to automatically set category from post  
object?

The best I could get right now is post\_path(post.category, post), but  
while it doesn’t look awful it still breaks all links in my app where  
most of the time I generate links using link\_to(post.title, post).

Cheers,  
Szymon
