Forum: Ruby on Rails Getting named parameters from routes.

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.
476d2a42689da3bd46375955fda053df?d=identicon&s=25 Jonathan Stott (Guest)
on 2007-05-21 15:28
(Received via mailing list)
I'm trying nested resources for a RESTful rails application.

So, I set my routes up like so:

map.resources :articles do |article|
  article.resources :comments
end

and when I "GET /articles/1", the 1 is assigned to params[:id]
But when I "GET /articles/1/comments/2", the 1 is :article_id, and the
2 becomes :id. Which works just fine. Except that if I want
before_filters to find the article and the comments, I need to have an
almost identical, but not quite, find_article function in the articles
and the comments function. One finds the article with param id, one
with param article_id.

Is there some way I could change things so that everything was known
by the 'full name' rather than the final parameter being shortened?

Jon
588ab1c0a5610a7e160a3b101abb91e6?d=identicon&s=25 MichaelLatta (Guest)
on 2007-05-21 17:30
(Received via mailing list)
I have not used this yet, but I would look at the source for
map.resources and see if there are options for controlling the name
used for the id.  It clearly generates different values for article
based on whether there is a block present.  You could always assign a
block to the comments map resources with nothing in it and see if that
forced it to comment_id.

Also, one of the people I talked with at RailsConf indicated that
nested resources were broken in edge.  Are you using edge or 1.2?

Michael
This topic is locked and can not be replied to.