This video指出可以保護通過控制器進入的輸入,但仍然可以通過型號和規格進行質量分配。但是,在3.2.8中使用strong_parameters時,我沒有看到這被記錄爲一項功能。導軌中的強參數3.2.8
據我所知,我需要在ActiveModel::ForbiddenAttributesProtection
中混入我的車型,並在config/application.rb
中設置config.active_record.whitelist_attributes = false
。我也從模型中調用了所有的attr_accessible
調用。
有或沒有mixin我得到質量分配錯誤。
ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: home_phone, cell_phone
我這麼想嗎?
如果你使用'attr_protected:home_phone,:cell_phone',他們將無法進行批量分配。 – VenkatK
不幸的是,我的模型中沒有'attr_protected'。但是我得到了同樣的錯誤。 –
@ brandon-hansen - 你有沒有看過Ryan Bates在這個主題上的railscast? http://railscasts.com/episodes/371-strong-parameters?view=asciicast – simonmorley