I have a resource, say Product
, which can be accessed by two different user classes: say Customer
and Admin
. There is no inheritance between these two.
I am using Devise for authentication:
# config/routes.rb
devises_for :customers
deviser_for :admins
I have these two controllers:
# app/controllers/customers/products_controller.rb
class Customers::ProductsController < ApplicationController
and
# app/controllers/admins/products_controller.rb
class Admins::ProductsController < ApplicationController
Now depending on who logs in (Customer
or Admin
), I want products_path
to point to the corresponding controller. And I want to avoid having customers_products_path
and admins_products_path
, that's messy.
So I have setup my routes as such
# config/routes.rb
devise_scope :admin do
resources :products, module: 'admins'
end
devise_scope :customer do
resources :products, module: 'customers'
end
This doesn't work. When I login as a Customer
, products_path
still points to Admins::ProductsController#index
as it is the first defined.
Any clue? What I want to do might simply be impossible without hacking.
UPDATE According to the code, it is not doable.