B
B
Bogdan2017-07-09 16:10:57
Ruby on Rails
Bogdan, 2017-07-09 16:10:57

Rails routing based on user role?

Hello. How to properly redirect in Rails depending on the selected role.
Now implemented like this
in application_controller.rb

def index
    redirect_root
  end

  def redirect_root
    if current_user_type == 'Admin'
      redirect_to admin_index_path
    else
      redirect_to institution_index_path
    end
  end

config/route.rb Maybe it's all possible to configure everything through only routing?
root 'application#index'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Andreev, 2017-07-09
@b0nn1e

And so it's normal.

A
Artur Bordenyuk, 2017-07-09
@HighQuality

before_action :redirect_root, only: [:index]

def index; end

protected

def redirect_root
# ...
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question