Hi –
On Sun, 22 Jun 2008, Tomek wrote:
Just wondering, in the tutorials I used it just showed using the paths
as bid_path and bids_path. Was this changed in recent versions, or has
it always been this way?
You’re using nested routes, and they always worked this way.
No – see my earlier email. Here’s an example, using Rails 1.2.3.
In routes.rb:
map.resources :auctions do |a|
a.resources :bids
end
In the console:
r = ActionController::Routing::Routes
=> [lots of output]
puts r.named_routes.map {|x| x[0].to_s }.grep(/bid/).sort
bid
bids
edit_bid
formatted_bid
formatted_bids
formatted_edit_bid
formatted_new_bid
new_bid
r.recognize_path(app.bids_path(:auction_id => 1), :method => :get)
=> {:controller=>“bids”, :action=>“index”, :auction_id=>“1”}
r.recognize_path(app.auction_bids_path(:auction_id => 1), :method
=> :get)
NoMethodError: undefined method `auction_bids_path’ for
#ActionController::Integration::Session:0x20e66ac
It may be ancient history (except for the concern about outdated
tutorials), but it really did once work that way.
David mentioned solutions to this above, but personally I think that
it’s better to use traditional approach. Especially when used in
views. Such routes as: new_auction_bid_path(@auction) are more
informative.
Common pattern is to use nested resources only in relation parent →
child, so using some experimental plugins isn’t best choice in my
opinion.
I don’t think using an experimental plugin in production is ever a
good idea, but I thought it was worth mentioning since we were
discussing the problem space it addresses.
look at this example:
map.resources :articles, :has_many => :comments
map.resources :authors, :has_many => :articles
what will be: article_path(@article) using this plugin?
/authors/5/articles/4 or /articles/5?
article_path has nothing to do with author_article_path. The plugin
sees no more ambiguity in this than the routing system in general
does.
The point of the plugin is that this:
author_article_path(@article)
will be interpreted by the plugin as if it were:
author_article_path(@article.author, @article)
In other words, it infers the route segments from the one object.
David
–
Rails training from David A. Black and Ruby Power and Light:
ADVANCING WITH RAILS June 16-19 Berlin
ADVANCING WITH RAILS July 21-24 Edison, NJ
See http://www.rubypal.com for details and updates!