Rails beginner
Rails beginner

Reputation: 14504

Rails devise STI or polymorphic, when having many models?

I have a problem. I cant figure out how to solve this authentication problem with devise and i dont know if i should use a polymorphic association in the models or STI.

I have 2 models like Teacher and Student. And i am trying to make a polymorphic association.

Here is my models:

   Teacher model:
        class Teacher < ActionController::Base
        has_one :user, :as => :profileable 
        devise :database_authenticatable, :registerable 
        end
    Student model:
        class Student < ActionController::Base
        has_one :user, :as => :profileable 
        devise :database_authenticatable, :registerable 
        end
    User model:
        class User < ActionController::Base
        belongs_to :profileable, :polymorphic => true
         attr_accessible :email, :password, :password_confirmation, :remember_me
        end

My routes.rb

School::Application.routes.draw do
  devise_for :users
  devise_for :teachers
  devise_for :students

I have created the views files for both Teachers and Students. But i cant figure out how to have 1 user table and differnts views and sign_up pages.

I want to have 2 sign up pages. One for Teacher and one for Student. I want the User table to store the login information(email, password ...).

How do I create such a thing with devise?

Best regards,

Rails beginner

Upvotes: 0

Views: 1213

Answers (1)

Ioannis Tziligkakis
Ioannis Tziligkakis

Reputation: 711

I would go for STI and use a Profile model storing user preferencies etc. As for different views per model take a look at the scoped views section.

Upvotes: 2

Related Questions