我在更新嵌套表单的属性时遇到问题。我把这个参数寄给我的控制器。但是
{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"sdfdsf", "office"=>{"worker_id"=>"5", "partecipants_attributes"=>{"0"=>{"id"=>"74", "is_presence"=>"true", "person_id"=>"83"}, "1"=>{"id"=>"75", "is_presence"=>"false", "person_id"=>"84"}}}, "commit"=>"salva", "action"=>"update", "controller"=>"etsw/course/offices", "id"=>"39"}
我有重复的结果为什么?我使用rails 3.2。我的模式下面的逻辑不是全部,因为是办公室项目
class Office < ActiveRecord::Base
attr_protected :id
belongs_to :worker, class_name: 'Worker', foreign_key: :worker_id
has_many :partecipants, class_name: 'Partecipant', foreign_key: :office_id
accepts_nested_attributes_for: partecipants,:allow_destroy => true
end
class Partecipant < ActiveRecord::Base
attr_accessible :id, is_presence, office_id, person_id
belongs_to :office, class_name: 'Office', foreign_key: :office_id
belongs_to :person, class_name: 'Person', foreign_key: :person_id
end
我使用rails 3.2 .. 我使用rails 3.2 ..我尝试使用强参数,但结果是相同的
@office.update_attributes(office_params)
private
def office_params
params.require(:office).permit(:worker_id, partecipants_attributes: [:id, :is_presence, :person_id])
end
答案 0 :(得分:0)