2011-01-15 24 views
0

AppointmentAppointmentモデルは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...が画面に表示されます。私は間違って何をしていますか?

答えて

0

<%= f.fields_for @client do |client_form| %> 

を試してみて、働いて、あなたのコントローラ

+0

@clientを初期化することを忘れないでください。ありがとうございました。 –

関連する問題