0
Appointment
のAppointment
モデルはclient_id
です。 Appointment
が作成されたときに、ユーザーがオートコンプリートフィールドにクライアントの名前を入力できるようにして、ユーザーが入力した名前にまだClient
というレコードがない場合は、新しいClient
が作成されます。マルチモデルフォームを使用できません
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 %>
(。私は他のフレームワークでは、このまったく同じことをやった)
はここに私のAppointment
モデルは次のようになります。理由は何もない<%= f.fields_for :client do...
が画面に表示されます。私は間違って何をしていますか?
で
@client
を初期化することを忘れないでください。ありがとうございました。 –