Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9090611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:24:49+00:00 2026-06-16T22:24:49+00:00

I have two kinds of users: Workers and Admins. I have a table of

  • 0

I have two kinds of users: Workers and Admins.
I have a table of workers and a table of admins.
I want to force the user to sign in before he can enter to the application pages.
so I added אם my ApplicationController the next line:

`before_filter :authenticate_user!`

now, I wrote a function, is called: is_worker that check if the user is found in the workers table. if so, redirect him to the page of the workers. if the user isn’t found, redirect him to the admin page.

I want that workers will not able to enter the admin pages, and the admins will not able to enter the workers pages.

so I think I should add: before_filter :is_worker to: workerscontroller and adminscontroller.

class ApplicationController < ActionController::Base
  protect_from_forgery

  before_filter :authenticate_user!

  def is_worker
     @email = current_user.email
     tag = Worker.where(:email => @email)
     if tag.nil?
        redirect_to '/admins'
     else
        redirect_to '/workers'
     end
  end
end

please correct me if I am wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:24:50+00:00Added an answer on June 16, 2026 at 10:24 pm

    It’s not very efficient. Assuming you’re using STI, create an is_worker? method like this:

    def is_worker?
      current_user.type == 'Worker'
    end
    

    Then in your controllers you can add a method like this:

    def redirect_after_sign_in
      if current_user.is_worker?
        redirect_to '/admins'
      else
        redirect_to '/workers'
      end
    end
    

    I’d make it a private method. Then you can call this method after the user successfully logs in.

    Even then you’ll want to protect your application at the controller level so that a worker can’t just go to the /admins URL and see admin data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two kinds of users: Admin and Worker. each user has role_ids: if
I'm working on an app where a user can have one of two kinds
I have two relational tables: the Profiles table which contains 3 kinds of user
I have a form, which allows the user to change dependencies between two kinds
General I have two kind of users, and one field (cluster) that I want
I have got two models, User and Event. I need two kind of relationship
Is this possible to have two (or more) different kinds of cells to be
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two columns say Main and Sub . (they can be of same
Let's say you have two kinds, Message and Contact, related by a db.ListProperty of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.