Ask A Question

Notifications

You’re not receiving notifications from this thread.

Multiple Devise Users sharing a dashboard

Stephen Sizer asked in Rails

Hi,

I have currently two Devise models Company and Contractor.

When they sign in I want to redirect them to a dashboard page. At the moment I have a before_action on the dashboard controller that only allows authenticate_company! so when a contractor signs in they can't view the dashboard.

Anyone done something like this before? Also is there an easy way to check which user is currently logged in so that I can show them different partial views?

Thanks in advance

Reply

Hey Stephen,

I would just make a custom before_action:

before_action :authenticate_company_or_contractor!

def authenticate_company_or_contractor!
  redirect_to root_path, alert: "You aren't allowed to do that" unless company_signed_in? || contractor_signed_in?
end

And voila. You're done. This is basically the exact same thing that authenticate_user! (or company or contractor, etc) implement behind the scenes. Nothin fancy!

Reply

Thanks for the super speedy response :)

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.