I have three models as follows:
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :role, polymorphic: true
validates_presence_of :first_name, :last_name, :email, :password,
:password_confirmation
end
student.rb
class Student < ActiveRecord::Base
has_one :user, as: :role, dependent: :destroy
accepts_nested_attributes_for :user
end
teacher.rb
class Teacher < ActiveRecord::Base
has_one :user, as: :role, dependent: :destroy
accepts_nested_attributes_for :user
end
I have user registration and login working as expected. However, I cannot figure out how to direct users to the appropriate homepage when they're logged in.
I handle routing for authenticated users as follows:
authenticated :user do
root to: "students#home", as: :user_root
end
Ideally if current user's role
attribute is a student, then it sets students#home
as :user_root
. If it's a teacher, then it sets teachers#home
as :user_root
. Is there any way to handle this purely in routes?