文档显示这是您标记和关联对象以进行销毁的方式,但它不起作用。怎么来的?
文档位于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
时间块.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