I have two different views and two different controllers in Rails app that I want the user to redirect to a specific one depending on whether a user is an admin or not.
I saw SO post like this one where it directs the page depending on whether user is authenticated or not, but I am looking for something like this (I am using devise):
#routes.rb
authenticated :user do
if user.admin
root to: "admin/first_page#index", as: :authenticated_root
else
root to "first_page#index", as: :authenticated_root
end
end
root to: "user/sign_in"
When the user signs in, it checks for user's admin privilege. If user is admin, go to admin/first_page#index
. If user isn't admin, go to first_page#index
.
I thought of using just one page and hide certain features for non-admin, something like: <% if user.admin%><%= secret_admin_feature %><% end %>
to keep it dry, but I have my own reasons why I choose not to keep it dry in this case.
Is it possible to do admin check from routes.rb? If yes, how can it be done? If not, what is a good alternative?