build
、fields_for
、およびを使用accepts_nested_attributes_for
して、新しい登録と同じフォームに新しい登録メモを作成しています (多くの登録メモがあります)。偉大な。
問題: 既存の登録の編集フォームで、別の新しい登録メモを作成したいのですが、既存の登録メモごとにフィールドを表示したくありません。
私はこれを持っています
class Registration < ActiveRecord::Base
attr_accessible :foo, :bar, :registration_notes_attributes
has_many :registration_notes
accepts_nested_attributes_for :registration_notes
end
この
class RegistrationsController < ApplicationController
def edit
@registration = Registration.find(params[:id])
@registration.registration_notes.build
end
end
ビューで私はこれをやっています:
<%= form_for @registration do |r| %>
<%= r.text_field :foo %>
<%= r.text_field :bar %>
<%= r.fields_for :registration_notes do |n| %>
<%= n.text_area :content %>
<% end %>
<% end %>
また、新しい登録メモ (良い)とその登録の既存の各登録メモ (いいえ) 用の空白のテキスト領域を作成しています。
その登録用の新しいメモのみを作成し、既存のものはそのままにしておく方法はありますか?