Forum: Ruby on Rails adding get var to generation of a named route

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
87fdabec748d7d2e11443671c20c6014?d=identicon&s=25 Peter Harkins (Guest)
on 2007-03-24 03:02
(Received via mailing list)
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 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?
4fbf24e8c9b1d2b71955b1e3dbfbc688?d=identicon&s=25 Nate Murray (Guest)
on 2007-04-02 21:24
(Received via mailing list)
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-h...
], but I haven't had a chance yet. I'm hoping there might be some help
in there.

Nate Murray
http://pasadenarb.com/
This topic is locked and can not be replied to.