0

I am using Rails 3.2.14, inherited_resource and strong_parameter gem.I just followed Strong Parameters in Rails 3.2.8 steps but i am getting error like below,

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

My code in controller is like that

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

Thanks for in advance

Community
  • 1
  • 1
Balachandran
  • 160
  • 2
  • 15

3 Answers3

1

You have to turn off attributes protection in your config/application.rb:

config.active_record.whitelist_attributes = false
Marek Lipka
  • 50,622
  • 7
  • 87
  • 91
0

Please check that all attributes that you want to updated are listed in the attr_accessible definition in your Mandat model:

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
spickermann
  • 100,941
  • 9
  • 101
  • 131
0

In my rails project,I use audited Gem.Refer Audited gem using strong Parameter.So in my model

Change

class Mandat < ActiveRecord::Base
    audited on: [:update]

to

class Mandat < ActiveRecord::Base
    audited :allow_mass_assignment => true,on: [:update]

then it will works perfectly.

Balachandran
  • 160
  • 2
  • 15