All threads / Multiple Devise Users sharing a dashboard

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

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!

Thanks for the super speedy response :)

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.