我正在使用Rails 3.2.14,inherited_resource和strong_parameter gem。我只是按照Strong Parameters in Rails 3.2.8步骤操作,但我收到的错误如下,
Can't mass-assign protected attributes:content, title, nature_bien_id, nature_transaction_id, nbr_chambres, nbr_pieces, section_id, city, zip, surface_habitable, surface_terrain
我在控制器中的代码就像那样
def create
@mandat = current_user.mandats.new(mandats_params)
end
private
def annonce_params
params.require(:annonce).permit(:created_at, :description, :image, :dpe, :nature_bien_id, :nature_transaction_id,:nbr_chambres, :nbr_pieces, :prix_net_acquereur, :section_id, :surface_habitable,:surface_terrain, :titre, :annonce_images_attributes, :user_id, :ville, :zip, :reference,:available_time, :is_valid, :close, :reasonclosing, :annonce_support_ids, :equipement_ids)
end
提前致谢
答案 0 :(得分:1)
您必须在config/application.rb
:
config.active_record.whitelist_attributes = false
答案 1 :(得分:0)
请检查attr_accessible
模型中的Mandat
定义中是否列出了您要更新的所有属性:
attr_accessible :created_at, :description, :image, :dpe, :nature_bien_id,
:nature_transaction_id,:nbr_chambres, :nbr_pieces, :prix_net_acquereur,
:section_id, :surface_habitable,:surface_terrain, :titre,
:annonce_images_attributes, :user_id, :ville, :zip, :reference,
:available_time, :is_valid, :close, :reasonclosing, :annonce_support_ids,
:equipement_ids
答案 2 :(得分:0)
在我的rails项目中,我使用了审计的Gem.Refer Audited gem using strong Parameter。所以在我的模型中
更改
class Mandat < ActiveRecord::Base
audited on: [:update]
到
class Mandat < ActiveRecord::Base
audited :allow_mass_assignment => true,on: [:update]
然后它将完美运作。