Ctpelnar1988 Ctpelnar1988 - 5 months ago 8
Ruby Question

How to route based on current_user?

If

current_user
is present, I would like to ask if
current_user.client_or_customer == "client"
. If so, I would like to show the
client_dashboard.html.erb
view, elsif
current_user.client_or_customer == "customer"
I would like to show the
customer_dashboard.html.erb


Is there a way to check in the routes if a param is present, or how to initialize the
current_user
?

Please excuse the limited knowledge of rails.

Answer

You shouldn't be actually checking params or reading the current user in routes. You should do this in a controller.

def index
  if current_user && current_user.client_or_customer == "client"
    render 'client_dashboard'
  elsif current_user && current_user.client_or_customer == "customer"
    render 'customer_dashboard'
  else
    render 'guest'
  end
end