Generating nested resource path

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:ingenerate’
/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:inrewrite’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:522:in `url_for’

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs