7
工作,我有同樣的問題,因爲這 one_destroy不Coocon寶石與軌道4
但是該解決方案並不能幫助我。 這裏是我的強烈PARAMS:
def request_params
params.require(:request).permit(:name, :address, :phone, :mobile, :type,
:filled_cartridges_attributes => [:cartridge_name,:client_id,,
\t \t \t \t :count,:_destroy,:id], \t \t \t \t \t \t \t
所以我有:_destroy和:ID。前一個人忘了補充:強烈的參數。添加一個id解決了他的問題。
這裏是我的要求型號:
has_many :filled_cartridges, inverse_of: :request, dependent: :destroy
\t accepts_nested_attributes_for :filled_cartridges, :reject_if => :all_blank, allow_destroy: true
這是PARAMS什麼樣子提交後:
request:
...some params....
filled_cartridges_attributes: !ruby/hash:ActionController::Parameters
'0': !ruby/hash:ActionController::Parameters
cartridge_name: HP LaserJet3000
_destroy: 'false'
id: '1'
'2': !ruby/hash:ActionController::Parameters
cartridge_name: new 9
_destroy: '1'
id: '13'
這裏ŧ他第二個應該被摧毀。 但它沒有。
如何爲模型分配參數? – BroiSatse
@BroiSatse你是什麼意思? – yerassyl
你在你的控制器中得到了你的參數,但是你對它們做了什麼?你能展示控制器的行爲嗎?另外,是否更新了第一個對象? – BroiSatse