# Generating nested resource path

**URL:** <https://www.ruby-forum.com/t/generating-nested-resource-path/115161>\
**Category:** Rails\
**Created:** [September 21, 2007, 8:01am UTC](https://www.ruby-forum.com/t/generating-nested-resource-path/115161 "2007-09-21T08:01:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [September 21, 2007, 8:01am UTC](https://www.ruby-forum.com/t/generating-nested-resource-path/115161/1 "2007-09-21T08:01:46Z")

</div>

I have a nested resourced called attachments:

(routes.rb)  
map.resources :content\_campaigns do |content\_campaigns|  
content\_campaigns.resources :attachments, :member =\> { :download  
=\> :get}  
end

But, I can’t seem to generate the new path after I create a new  
attachment:

(attachments\_controller.rb)

format.xml { head :created, :location =\>  
attachment\_url(@attachment) }

I get this trace:

ActionController::RoutingError (attachment\_url failed to generate from  
{:action=\>“show”, :content\_campaign\_id=\>“7”,  
:controller=\>“attachments”},  
expected: {:action=\>“show”, :controller=\>“attachments”}, diff:  
{:content\_campaign\_id=\>“7”}):  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/routing.rb:1273:in `raise_named_route_error' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/routing.rb:1245:in`generate’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/url\_rewriter.rb:104:in `rewrite_path' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_controller/url_rewriter.rb:69:in`rewrite’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/  
action\_controller/base.rb:522:in `url\_for’

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [September 21, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/generating-nested-resource-path/115161/2 "2007-09-21T17:07:44Z")

</div>

eggie5 wrote:

> I have a nested resourced called attachments:
> 
> (routes.rb)  
> map.resources :content\_campaigns do |content\_campaigns|  
> content\_campaigns.resources :attachments, :member =\> { :download  
> =\> :get}  
> end
> 
> But, I can’t seem to generate the new path after I create a new  
> attachment:
> 
> (attachments\_controller.rb)
> 
> format.xml { head :created, :location =\>  
> attachment\_url(@attachment) }

Don’t you need attachment\_url(@campaign, @attachment) since it’s nested?

mike
