我控制器呼籲更新這個模型方法:設置PARAM屬性明確,不更新與update_attributes方法調用
def update_standard(param_attributes)
...
if param_attributes[:is_legacy] == true
param_attributes[:foo_type_id] = 2
end
update_attributes(param_attributes)
end
foo_type_id
應該覆蓋任何在表單中輸入的用戶,但用戶的選擇是什麼寫入D B。當is_legacy
爲真時,我如何執行foo_type_id
爲2?
你應該檢查以確保'params [:is_legacy]'實際返回'true'而不是''true「' - 確定參數總是字符串。 – Veraticus
工作。如果你願意,輸入你的建議作爲答案,我會接受它。 –
完成,很高興幫助! – Veraticus