これはレール2.3にあります。うまくいけば問題のポイントに到達するために、私はたくさんのコードを切り取りました。1つ以上のEmailPreferencesを持つUserオブジェクトで[保存]をクリックすると、次のようになります。
1つのエラーにより、このユーザーを保存できませんでした
次のフィールドに問題がありました。
通知タイプはリストに含まれていません
class User < ActiveRecord::Base
has_many :email_preferences
accepts_nested_attributes_for :email_preferences
attr_accessible :email_preferences_attributes
end
class EmailPreference < ActiveRecord::Base
# receives is a boolean, notification_type is a string.
attr_accessible :user_id, :receives, :notification_type
belongs_to :user
end
class UsersController < ApplicationController
def new
@user = User.new
@user.email_preferences.build :receives=>false, :notification_type=>"outage"
end
def edit
@user = User.find(params[:id])
end
end
# app/views/user/_form.rhtml
<% form_for :user, user do |f| -%>
<% f.fields_for :email_preferences do |preference_form| -%>
<dd>
<%= preference_form.check_box :receives %>
<!-- I just want to display the notification type. I do not want to edit it. -->
<%= preference_form.object.notification_type %>
</dd>
<% end -%>
<%= form_submit f.object, :cancel => companies_path %>
<% end -%>
編集
さらに良いことに、あまり役に立たないエラーメッセージをデバッグするにはどうすればよいでしょうか。