Rails beginner
2010-Dec-30 18:38 UTC
Rails devise STI or polymorphic, when having many models?
Hello
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 Virksomhed < 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
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Tim Shaffer
2010-Dec-30 21:13 UTC
Re: Rails devise STI or polymorphic, when having many models?
On Thursday, December 30, 2010 1:38:18 PM UTC-5, Rails beginner wrote:> > Hello > > 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 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 ...). > > In that case, you want to use STI.To get that working, your user class would inherit from ActiveRecord::Base, but your Student and Teacher class would inherit from User. No associations necessary. class User < ActiveRecord::Base class Student < User class Teacher < User -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.