Ruby on rails Can';不能让多模型表单工作

Ruby on rails Can';不能让多模型表单工作,ruby-on-rails,forms,Ruby On Rails,Forms,我有一个预约模型,其中每个预约都有一个客户id。创建约会时,我希望用户能够在自动完成字段中键入客户的姓名,以便在用户键入的姓名没有客户记录时创建新的客户。(我在其他框架中也做过同样的事情。) 以下是我的预约模型的外观: class Appointment < ActiveRecord::Base has_many :appointment_services belongs_to :client accepts_nested_attributes_for :client end

我有一个
预约
模型,其中每个
预约
都有一个
客户id
。创建
约会
时,我希望用户能够在自动完成字段中键入客户的姓名,以便在用户键入的姓名没有
客户
记录时创建新的
客户
。(我在其他框架中也做过同样的事情。)

以下是我的
预约
模型的外观:

class Appointment < ActiveRecord::Base
  has_many :appointment_services
  belongs_to :client
  accepts_nested_attributes_for :client
end
<%= form_for(@appointment) do |f| %>
  <% if @appointment.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@appointment.errors.count, "error") %> prohibited this appointment from being saved:</h2>

      <ul>
      <% @appointment.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <%= f.fields_for :client do |client_form| %>
    <div class="field">
      <%= client_form.label :name %>
      <%= client_form.text_field :name %>
    </div>
  <% end %>
班级预约
下面是我的表单的外观:

class Appointment < ActiveRecord::Base
  has_many :appointment_services
  belongs_to :client
  accepts_nested_attributes_for :client
end
<%= form_for(@appointment) do |f| %>
  <% if @appointment.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@appointment.errors.count, "error") %> prohibited this appointment from being saved:</h2>

      <ul>
      <% @appointment.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <%= f.fields_for :client do |client_form| %>
    <div class="field">
      <%= client_form.label :name %>
      <%= client_form.text_field :name %>
    </div>
  <% end %>

禁止保存此约会:
由于某种原因,
中没有任何内容请尝试


别忘了在控制器中初始化
@客户端