redirect users by the tables that they belong to
I have two tables: workers_table and admins_table.
I have two controllers and I use devise (sign_in, sign_up...).
in the controllers of workers and admins.
assume I have the email of the user that signed in:
@email = current_user.email
I want to check where @email is found:
if it's found in the workers table, so redirect him to the index.html.erb of workers (and he can't enter to index.html.erb of the admins).
if it's found in the admins table, so redirect him to the index.html.erb of admins (and he can't enter to index.html.erb of the workers).
I know how to check if the user belongs to workers_table or admins_table.
but where should I check which table the user belongs to? should I define another controller?
please guide me.
application_controller.rb would be a good place to define the authenticate_user functionality
another place could be a sessions_controller.rb if you have it
at the very least you could have an ensure_admin method for your admins_controller to add to the before_filter, and if they are not an admine, you could redirect_to workers#index
I'm new to rails, so i'm unsure as to the conventional way to do this, but the above is how I might do it.