Carlos Santana wrote: > I am using nested resources as follows: > map.resources :topics do |topics| > topics.resources :items do |items| > items.resources :attachments > end > end > > When I generate a RESTful path for new item in the console: > app.new_topic_item_path(2) then I get correct path as > '/topics/2/items/new'. > > However, for the new attachment I am getting error: > app.new_topic_item_attachment_path(22) gives - > ActionController::RoutingError: new_topic_item_attachment_url failed to > generate from {:action=>"new", :controller=>"attachments", > :topic_id=>22}, expected: {:controller=>"attachments", :action=>"new"}, > diff: {:topic_id=>22} > > from > /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/routing/route_set.rb:375:in > `raise_named_route_error' > from > /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/routing/route_set.rb:339:in > `generate' > from > /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/url_rewriter.rb:131:in > `rewrite_path' > from > /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/url_rewriter.rb:110:in > `rewrite_url' > from > /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/url_rewriter.rb:88:in > `rewrite' > from > /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/integration.rb:218:in > `url_for' > from (eval):17:in `new_topic_item_attachment_path' > from (irb):5. > > - - - - - > > Why is it failing and how to fix this? > And, why is it generating '{:action=>"new", :controller=>"attachments", > :topic_id=>22}' ? Shouldn't it pass item_id rather than topic_id? > > Any clues? > > - > Thanks, > CS.
Figured it out: I did new_topic_item_attachment_path and got an error: ''ActionController::RoutingError: new_agenda_item_attachment_url failed to generate from {:action=>"new", :controller=>"attachments"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["agendas", :agenda_id, "items", :item_id, "attachments", "new"] - are they all satisfied?'' So I need to pass both topic and item id. But isn't item associated with the topic resource? Why do I need to pass both ids? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---