Pregunta

Estoy trabajando en hacer una asociación polimórfica de un número de teléfono a un voluntario (y más tarde a otras cosas), actualmente estoy atascado con el siguiente error:

uninitialized constant HumanVolunteer::PrimaryPhone
app/controllers/human_volunteers_controller.rb:44:in `new'
app/controllers/human_volunteers_controller.rb:44:in `create'

Aquí está mi modelo de foneneberos:

class PhoneNumber < ActiveRecord::Base
  attr_accessible :notes, :number

  belongs_to :phone, :polymorphic => true
end

Y aquí está mi modelo HumanVolunteers:

class HumanVolunteer < ActiveRecord::Base

  attr_accessible :firstName, :lastName, :homeaddressid, :notes, :status, :workdaddressid, :home_adr, :work_adr, :primaryPhone
  has_one :primaryPhone, :as => :phone

  def home_adr=(home_adr_arg)
    # Home ADR
    home_adr = Address.new(home_adr_arg)
    if home_adr.save 
      self.homeaddressid = home_adr.id
    end
  end

  def work_adr=(work_adr_arg)
    # Work ADR
    work_adr = Address.new(work_adr_arg)
    if home_adr.save 
      self.workaddressid = work_adr.id
    end
  end
end

y mi esquema para números de teléfono y Human_Volunteers:

Tabla: Human_Volunteers

id  integer 
status  character varying(255)  
homeaddressid   integer     
workdaddressid  integer     
notes   text        
created_at  timestamp without time zone 
updated_at  timestamp without time zone 
firstName   character varying(255)      
lastName    character varying(255)  

Tabla: Phone_Numbers

id  integer 
number  character varying(255)          
notes   text        
created_at  timestamp without time zone     
updated_at  timestamp without time zone     
phone_id    integer     
phone_type  character varying(255)

El error está sucediendo cuando intento crear un nuevo voluntario bajo cualquier entrada aquí es mi solicitud de ejemplo actual:

{"human_volunteer"=>{"primaryPhone"=>"5555555555",
 "firstName"=>"",
 "notes"=>"",
 "work_adr"=>{"city"=>"",
 "state"=>"",
 "zipcode"=>"",
 "line1"=>"",
 "line2"=>""},
 "home_adr"=>{"city"=>"",
 "state"=>"",
 "zipcode"=>"",
 "line1"=>"",
 "line2"=>""},
 "lastName"=>""},
 "authenticity_token"=>"RCPTxZpzytYXcDEUo0czRxpI4A3Qw1ErwcIBJ92RhLA=",
 "utf8"=>"✓"}

Nota: También tengo una clase de dirección, pero ya tengo ese trabajo, así que no tuviera su poste con él.

de navegar por el foro en el Foro, parecía que el principal problema para otros era la planaización, pero por lo que puedo decir, tengo todo lo plaalizado correctamente.

También intenté agregar un teléfono_id o la ThonePhone_ID a la tabla de voluntarios humanos, pero no ayudó.

Muchas gracias, - Ken

¿Fue útil?

Solución

Su has_one necesita saber qué clase se refiere a.

  has_one :primary_phone, :class_name => "PhoneNumber", :as => :phone

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top