← Back to Upcase

Routes clashing - user and dashboard

(Dan Weaver) #1

I have different user types going to different dashboard pages using a StaticPages controller.

In routes.rb:

get "owner",      to: 'static_pages#admin'
get "superadmin", to: 'static_pages#admin'
get "admin",      to: 'static_pages#admin'
get "teacher",    to: 'static_pages#teacher'
get "family",     to: 'static_pages#family'

This is primarily for the neatness of URLs. Admin users see myapp.com/admin, etc.

I’m using Devise for authentication but I’m managing users within the app with a CRUD interface so I’ve added the user resources to my routes:

resources :admins
resources :teachers
resources :families

This was all working fine until I added the admin resources. Now my admin_path fails because it looks for a #show action in the admins controller.

I’m not sure why the teacher and family routes didn’t fail too?

(Dan Weaver) #2

I solved this by ensuring that my static page routes were defined at the top of routes.rb so that subsequent resource routes didn’t conflict.

I know I still have to change my naming to make things less problematic but at least it’s working again now.