ドキュメントには、これがオブジェクトに破壊のマークを付けて関連付ける方法であることが示されていますが、機能していません。どうして?
ドキュメントはhttp://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.htmlにあり、 以下を示しています。
member.avatar_attributes = { :id => '2', :_destroy => '1' }
member.avatar.marked_for_destruction? # => true
member.save
member.reload.avatar # => nil
私は持っています:
アポイントメント.rb
class Appointment < ActiveRecord::Base
belongs_to :time_block
end
time_block.rb
class TimeBlock < ActiveRecord::Base
has_one :appointment
accepts_nested_attributes_for :appointment, :allow_destroy => :true,
:reject_if => :all_blank
end
(rdb:144) @time_block.appointment_attributes = {"_destroy"=>"1", "id"=>"48"}
(rdb:144) p @time_block.appointment.marked_for_destruction?
false