1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Dan
  • 199
  • 3
  • 12

2 Answers2

0

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
  • 9,719
  • 2
  • 37
  • 41
  • 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 Jul 23 '10 at 22:36
  • 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 Jul 24 '10 at 03:44
0

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
  • 17,702
  • 4
  • 51
  • 54
  • well my status isn't a resource, the reports are. there isn't such thing in my project as a status id. – Dan Jul 23 '10 at 22:33
  • Then please update your post so that the question mentions what it is you're trying to accomplish with "status_path". – jdl Jul 24 '10 at 06:04