Вложенные атрибуты для рельсов ассоциации

У меня есть две модели, жалоба и компания. жалобаbelongs_to а такжеaccepts_nested_attributes для компании и компанииhas_many Жалобы.

# Models

class Complaint < ActiveRecord::Base
  attr_accessible :complaint, :date, :resolved

  belongs_to :user, :class_name => 'User', :foreign_key => 'id'
  belongs_to :company, :class_name => 'Company', :foreign_key => 'id'
  has_many :replies

  accepts_nested_attributes_for :company

end

class Company < ActiveRecord::Base
  attr_accessible :name

  has_many :complaints, :class_name => 'Complaint', :foreign_key => 'id'
  has_many :branches, :class_name => 'Branch', :foreign_key => 'id'
  belongs_to :industry

end

В контроллере жалоб я пытаюсь построить компанию новым методом.

# Complaint Controller

class ComplaintsController < ApplicationController
...
def new
    @complaint = Complaint.new
    @complaint.build_company

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @complaint }
    end
  end
...
end

В форме я добавил поле для добавления атрибута имени в компанию.

# Complaint Form


  
    
       prohibited this complaint from being saved:

      
      
        
      
      
    
  

  
    <br>
     5 %>
  
  
    <br>
    
  

  
    
      <br>
      
    
  

  
    
      
      
    
  

  
    
  

Форма отправляется, но сохраняется только жалоба. Пользовательский ввод для компании игнорируется. Почему выигралт это создать новую компанию?

Ответы на вопрос(1)

Ваш ответ на вопрос