mercredi 16 novembre 2016

Routing based on role - Rails

Rails 3.2

I have 2 sets of controllers, one for admin and one for regular users.

When an admin logs in, I want them to go to the index method, in controllers/admin/tickets_contoller.rb

I have the following in my routes.rb:

namespace :admin do
  root to: 'tickets#index'
  ....

and in my application_controller.rb, I have:

def after_sign_in_path_for(resource_or_scope)
  if current_user && current_user.current_company
    view_context.can? :index, :admin
      admin_root_path
  end
end

But, when I log in as admin, it seems to be going to the standard tickets_controller, not the admin/tickets_controller

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire