Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
June 20, 2024
Here’s a guide to set up redirection for admins and regular users to different home pages after login in a Rails application:
Override the after_sign_in_path_for method in your ApplicationController:
class ApplicationController < ActionController::Base protect_from_forgery with: :exception def after_sign_in_path_for(resource) if resource.admin? rails_admin_path # Redirect admin to RailsAdmin dashboard else user_home_path # Redirect regular users to user home page end end end
Ensure routes are defined in config/routes.rb:
Rails.application.routes.draw do mount RailsAdmin::Engine => '/admin', as: 'rails_admin' get 'user_home', to: 'users#home', as: 'user_home' devise_for :users root 'home#index' end
Add a home action to UsersController:
class UsersController < ApplicationController before_action :authenticate_user! def home end end
Create the view for the user home page:
Welcome to your home page, <%= current_user.email %>!