'Rails => routing index to two different pages depending on the current_user

I'm using Rails and I have two views in bookings (clients and trainers). I'm trying to route from index to client or trainers depending on who is the current_user.

If I'm a client, route index to trainers If I'm a trainer, route index to clients

class BookingsController < ApplicationController
  def index

  end

  def clients
    @bookings = Booking.where(client: current_user)
    @clients = current_user.bookings.map(&:client)
  end

  def trainers
    @trainers = current_user.bookings.map(&:user)
  end

end
Rails.application.routes.draw do
  resources :bookings do
    collection do
      get "/clients", to: "bookings#clients", as: "clients"
      get "/trainers", to: "bookings#trainers", as: "trainers"
    end
    resources :shared_training_plans, except: [:new]
  end
end


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source