First here’s my current setup:
models/user.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
has_many :events
end
models/event.rb
class Event < ActiveRecord::Base
belongs_to :user
end
So, this works in the sense that a user have many events that s/he can CRUD. Anyone that is not logged in can only view and list all the events.
From this initial setup, I now have another set of users that are attendees and the current users are now actually event managers instead of just a generic user. Essentially, I now have two models that are both users (since they can both log in/sign up and have the same fields) and I was thinking that event should read something like:
models/event.rb
class Event < ActiveRecord::Base
belongs_to :manager
has_many :attendees, :through => :attendance # attendance is a join model
end
but I don’t want to create a separate table for managers and attendees and I was thinking of sub classing the user model but I’m not particularly sure about how to go about it. I was looking into the :as and :polymorphic parameters in AR but I’m still not quite sure on how to do it. Help?
What you are looking for is called Single Table Inheritance. Here is one resource on the subject. There are many more. Just google for “Rails Single Table Inheritance”.