Forum: Ruby on Rails How to do /tag/:tag/articles with map.resources correctly ?

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.
Qw E. (Guest)
on 2007-02-18 03:48
Hello,

Currently I have

config/routes.rb:

<pre>
  map.resources :tags do |tags|
    tags.resources :articles, :name_prefix => 'tag_'
  end
</pre>

with tag_articles_path(tag_name) it maps like I want to:

/tags/blah/articles

.. but if I have a tag selected. If I do, for example,
tag_articles_path(:order => 'top') and at this moment tag_id is nil, I
get this error:

tag_articles_url failed to generate from {:action=>"index",
:controller=>"articles"} - you may have ambiguous routes, or you may
need to supply additional parameters for this route.  content_url has
the following required parameters: ["tags", :tag_id, "articles"] - are
they all satisifed?

I think, this is right... But what should I do if I need to use all this

tag_new_article_path, tag_articles_path(:order => 'top'), etc ?

I know, I can write all helper methods I need or do something like

current_tag ? tag_articles_path : articles_path

or

articles_path(:tag => current_tag), articles_path(:tag => current_tag,
:order ..) - in this case I do not know how to get good looking urls
(/tag/tag_name/articles)

maybe there are a better way to handle this ?

Thank you.
This topic is locked and can not be replied to.