views:

74

answers:

2

I'm attempting to use nested controllers that have restful pathing, so that I'm all organized and such. Here's a copy of my routes.rb so far:

 map.root :controller => "dashboard"

  map.namespace :tracking do |tracking|
    tracking.resources :companies
  end

  map.namespace :status do |status|
    status.resources :reports
  end

Links to children controller paths work fine right now,

<%= link_to "New Report", new_status_report_path, :title => "Add New Report" %>

But my problem ensued when I tried to map to just the parent controller's index path.

<%= link_to "Status Home", status_path, :title => "Status Home" %>

I end up getting this when I load the page with the link:

undefined local variable or method `status_path' 

Are my routes set correctly for this kind of link?

UPDATE: I should add that no data is associated with the parent "status" controller. It merely acts as the category placeholder for the rest of the controllers associated with statuses, eg: reports.

A: 

If you want /status to go to the status controller it should be a resource, not a namespace. You nest resources in much the same way:

map.resource :status do |status|
  status.resources :reports
end
mckeed
perhaps I'm confused on what a namespace is, but my "status" category doesn't have any data directly associated with it. It's just a placeholder category for organization's sake. What I'm trying to do is just have it render a landing page for that category with links to things like reports etc.
Dan
A resource doesn't have to have data associated with it. If you want there to be a page at "/status", you have to route it somewhere. If you want to keep your routes restful, you should make a StatusesController and make status a singular resource as above. Then /status will go to the show method of StatusesController. On the other hand, sometimes apps will have a PagesController for all the pages that don't fit well as resource routes, you can route it like `map.status "/status", :controller => :pages, :action => :status`
mckeed
A: 

A namespace isn't a resource.

map.resources :statuses do |status|
  status.resources :reports
end

Also, your call to status_path needs an ID.

status_path(:id => @status.id)

or

status_path(@status)

jdl
well my status isn't a resource, the reports are. there isn't such thing in my project as a status id.
Dan
Then please update your post so that the question mentions what it is you're trying to accomplish with "status_path".
jdl