Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following route:

get "/:user_name/things/:thing_name" => "things#show", :as => "show_user_thing"

Thing belongs to user. So with just an instance of thing I have both parameters. However, when using the route helpers, I'm forced to specify each segment separately like so:

show_user_thing_path(@thing.user, @thing)

This sucks. I'd much rather do just this:

show_user_thing_path(@thing)

But how do I do this the 'route helper way'? I'd love to still use all the rails goodies for route's like these. Any ideas?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I feel your pain. In the cases where I uses the url helper a lot, I just write my own helper.

def show_thing_by_user_path(thing)
    show_user_thing_path(thing.user, thing)
end 

Of course you'd have to modify it slightly to include any options and formatting, but I think you get the idea of what I'm saying.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["                  <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2015 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2015.5.5.2551\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </nosc"], "copyright__copyright__copyright": ["here I uses the url helper a lot, I just write my own helper.\n\ndef show_thing_by_user_path(thing)\n    show_user_thing_path(thing.user, thing)\nend \n\nOf course you'd have to modify it slightly to include any options and formatting, but I think you get the idea of what I'm saying.\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}