# Adding get var to generation of a named route

**URL:** <https://www.ruby-forum.com/t/adding-get-var-to-generation-of-a-named-route/89945>\
**Category:** Rails\
**Created:** [March 24, 2007, 3:02am UTC](https://www.ruby-forum.com/t/adding-get-var-to-generation-of-a-named-route/89945 "2007-03-24T03:02:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [March 24, 2007, 3:02am UTC](https://www.ruby-forum.com/t/adding-get-var-to-generation-of-a-named-route/89945/1 "2007-03-24T03:02:11Z")

</div>

I have an ActiveResource named Discussion. In my views, I often call  
discussion\_path(@discussion) and I’d like to add on the post count  
(discussion.posts.count) as a get var. I’m want my urls to be like:  
[http://nearbygamers.com/discussions/14?posts=3](http://nearbygamers.com/discussions/14?posts=3) so that folks who’ve  
read a forum see blue links for discussions that have had posts added  
to them.

I’ve tried adding options to the discussion\_path call in my views  
which just blows up with various unhelpful messages (either that  
“discussion url failed to generate” or a call to nil.to\_sym). I’ve  
tried writing my own discussion\_path helper with similar results. Any  
suggestions?

---

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [April 2, 2007, 9:24pm UTC](https://www.ruby-forum.com/t/adding-get-var-to-generation-of-a-named-route/89945/2 "2007-04-02T21:24:17Z")

</div>

I’m having this exact same problem.

I have a route of:

map.content ‘sites/:site\_short\_name/\*file’,  
:controller =\> ‘sites’,  
:action =\> ‘content’,  
:requirements =\> { :site\_short\_name =\> /some\_regex/ }

And I try to call

content\_url :file =\> “search”

and it also “blows up” and says:

ActionView::TemplateError: content\_url failed to generate from  
{:action=\>“content”, :file=\>“search”, :controller=\>“sites”}, expected:  
{:action=\>“content”, :controller=\>“sites”}, diff: {:file=\>“search”}

I’ve looked into the rails source and this seems to be coming from:

actionpack/lib/action\_controller/routing.rb line 1280 ( I have Rails  
SVN revision REVISION\_{2007-02-19}, so it’s 1.2-ish ).

The exception seems to be raised from line 1242 in the same file  
because  
path = named\_route.generate(options, merged, expire\_on)  
is returning nil…

I’m planning on reading Jamis’ article: Under the hood: route  
generation in Rails [  
[http://weblog.jamisbuck.org/2006/10/16/under-the-hood-route-generation-in-rails](http://weblog.jamisbuck.org/2006/10/16/under-the-hood-route-generation-in-rails)  
], but I haven’t had a chance yet. I’m hoping there might be some help  
in there.

Nate M.  
[http://pasadenarb.com/](http://pasadenarb.com/)
