views:

16

answers:

1

register < user

admin < user

class project has_many :admin, :class => 'User', :conditions => "type = 'admin'" has_many :registers, :class => 'User', :conditions => "type = 'registers'"

the problem here is, when I use project to has_many create a register or admin, it doesn't automate fill object class into type filed.

like this: project.admins.new.

how to fix this problem ?

+1  A: 

You should be able to specify the has_many relationships directly, without needing to tell Rails that the class is User. Like so:

class User < ActiveRecord::Base
  belongs_to :project
end

class Register < User    
end

class Admin < User
end

class Project < ActiveRecord::Base
  has_many :admins
  has_many :registers

  def make_new_admin
    ad = admins.create(:name => "Bob")
    # ad.type => "Admin"
  end
end
Chris