1

This is a design problem that I am trying to figure out. I will explain what I have right now, and what I would like to have:

1. Actual design

I have a defined a resources :users and by doing so I have defined different actions such as new, create and update in the Users controller. This is working as expected by following urls like users/new , users/:id, etc... Now I want to go one step forward, and I want to be able to do the following...

2. What am I looking for

I want to be able to have a route like this:

users/overview/profile - This should be equivalent to `users/:id` (show action) 
users/overview/network - This should be equivalent to users/:id/network (list of networks for that user)

3. My idea

My first idea was to define something like this:

resource :users do
 namespace :overview do
  resource :networks
 end
end

But this would work for urls like: users/:id/overview/networks and I don't want the user id to be shown in the URL. So my questions are:

1 - How can I deal with users/overview/networks instead of users/:id/overview/networks , assuming that I can get the user id from session.

2 - How can I be able to manage URLs like this: users/overview/profile where actually a profile is just the show method of users/:id Right now I have defined all the actions in the users controller and everything is working fine (new,delete,create,update...) I just don't know how to move into that "namespace" overview/profile

Hommer Smith
  • 26,772
  • 56
  • 167
  • 296

2 Answers2

0

I have tried same thing you tried, and it is returning your desired results only, not sure what is your problem. Posting rake routes result here.

users_overview_networks POST        /users/overview/networks(.:format)         {:action=>"create", :controller=>"overview/networks"}
new_users_overview_networks GET         /users/overview/networks/new(.:format)     {:action=>"new", :controller=>"overview/networks"}
edit_users_overview_networks GET         /users/overview/networks/edit(.:format)    {:action=>"edit", :controller=>"overview/networks"}
GET         /users/overview/networks(.:format)         {:action=>"show", :controller=>"overview/networks"}
PUT         /users/overview/networks(.:format)         {:action=>"update", :controller=>"overview/networks"}
DELETE      /users/overview/networks(.:format)         {:action=>"destroy", :controller=>"overview/networks"}
users POST        /users(.:format)                           {:action=>"create", :controller=>"users"}
new_users GET         /users/new(.:format)                       {:action=>"new", :controller=>"users"}
edit_users GET         /users/edit(.:format)                      {:action=>"edit", :controller=>"users"}
GET         /users(.:format)                           {:action=>"show", :controller=>"users"}
PUT         /users(.:format)                           {:action=>"update", :controller=>"users"}
DELETE      /users(.:format)                           {:action=>"destroy", :controller=>"users"}
rajibchowdhury
  • 5,264
  • 2
  • 14
  • 7
0
  scope :path => 'users/overview' do
    match ':id/profile', :to => 'users#show'
    match ':id/network', :to => 'users#network'
  end 
Sandip Ransing
  • 7,583
  • 4
  • 37
  • 48