ruby on rails - Forbidden attribute error when updating object with hash.keys, hash.values -


i'm getting following error when try update 1 of objects:

activemodel::forbiddenattributeserror  extracted source (around line #21):        def sanitize_for_mass_assignment(attributes)         if attributes.respond_to?(:permitted?) && !attributes.permitted?           raise activemodel::forbiddenattributeserror         else           attributes         end 

the logic in controller following:

  params["employeeschedules"].each |key,value|  #this gets params each scheduleid values = 1=> { "hrs" => 3}}    @update_hash = value   end   logger.debug "@params = #{@update_hash}"   logger.debug "keys= #{@update_hash.keys} values = #{@update_hash.values}"    if employeeschedule.update(@update_hash.keys, @update_hash.values)    #if employeeschedule.update([19,67], [{"hrs" => "1"}, {"hrs" =>"2"}]) 

if use line instead of 1 @update_hash.keys @update_hash.values, works though keys/values subset of keys/values in update hash.

if employeeschedule.update([19,67], [{"hrs" => "1"}, {"hrs" =>"2"}])  #this works if employeeschedule.update(@update_hash.keys, @update_hash.values) #this gives error above 

summary of params , hash values

parameters: {"utf8"=>"✓", "authenticity_token"=>"tveh6o9jtvckrfhbaeijbwcmb/ycqotzfmr0yrvk8jpfemggd6istgzraradlkcgaabrw1iz6wjzgz9o1gsr9q==", "employeeschedules"=>{"schedules"=>{"59"=>{"hrs"=>""}, "19"=>{"hrs"=>""}, "67"=>{"hrs"=>""}, "107"=>{"hrs"=>""}, "27"=>{"hrs"=>""}, "75"=>{"hrs"=>""}, "115"=>{"hrs"=>""}, "64"=>{"hrs"=>""}, "24"=>{"hrs"=>""}, "72"=>{"hrs"=>""}, "112"=>{"hrs"=>""}, "32"=>{"hrs"=>""}, "80"=>{"hrs"=>""}, "120"=>{"hrs"=>""}, "60"=>{"hrs"=>""}, "20"=>{"hrs"=>""}, "68"=>{"hrs"=>""}, "108"=>{"hrs"=>""}, "28"=>{"hrs"=>""}, "76"=>{"hrs"=>""}, "116"=>{"hrs"=>""}, "63"=>{"hrs"=>""}, "23"=>{"hrs"=>""}, "71"=>{"hrs"=>""}, "111"=>{"hrs"=>""}, "31"=>{"hrs"=>""}, "79"=>{"hrs"=>""}, "119"=>{"hrs"=>""}, "58"=>{"hrs"=>""}, "18"=>{"hrs"=>""}, "66"=>{"hrs"=>""}, "106"=>{"hrs"=>""}, "26"=>{"hrs"=>""}, "74"=>{"hrs"=>""}, "114"=>{"hrs"=>""}, "65"=>{"hrs"=>""}, "25"=>{"hrs"=>""}, "73"=>{"hrs"=>""}, "113"=>{"hrs"=>""}, "33"=>{"hrs"=>""}, "81"=>{"hrs"=>""}, "121"=>{"hrs"=>""}}}, "actiontype"=>"update"}

@params = {"59"=>{"hrs"=>""}, "19"=>{"hrs"=>""}, "67"=>{"hrs"=>""}, "107"=>{"hrs"=>""}, "27"=>{"hrs"=>""}, "75"=>{"hrs"=>""}, "115"=>{"hrs"=>""}, "64"=>{"hrs"=>""}, "24"=>{"hrs"=>""}, "72"=>{"hrs"=>""}, "112"=>{"hrs"=>""}, "32"=>{"hrs"=>""}, "80"=>{"hrs"=>""}, "120"=>{"hrs"=>""}, "60"=>{"hrs"=>""}, "20"=>{"hrs"=>""}, "68"=>{"hrs"=>""}, "108"=>{"hrs"=>""}, "28"=>{"hrs"=>""}, "76"=>{"hrs"=>""}, "116"=>{"hrs"=>""}, "63"=>{"hrs"=>""}, "23"=>{"hrs"=>""}, "71"=>{"hrs"=>""}, "111"=>{"hrs"=>""}, "31"=>{"hrs"=>""}, "79"=>{"hrs"=>""}, "119"=>{"hrs"=>""}, "58"=>{"hrs"=>""}, "18"=>{"hrs"=>""}, "66"=>{"hrs"=>""}, "106"=>{"hrs"=>""}, "26"=>{"hrs"=>""}, "74"=>{"hrs"=>""}, "114"=>{"hrs"=>""}, "65"=>{"hrs"=>""}, "25"=>{"hrs"=>""}, "73"=>{"hrs"=>""}, "113"=>{"hrs"=>""}, "33"=>{"hrs"=>""}, "81"=>{"hrs"=>""}, "121"=>{"hrs"=>""}}

hash value {59=>{"hrs"=>""}, 19=>{"hrs"=>""}, 67=>{"hrs"=>""}, 107=>{"hrs"=>""}, 27=>{"hrs"=>""}, 75=>{"hrs"=>""}, 115=>{"hrs"=>""}, 64=>{"hrs"=>""}, 24=>{"hrs"=>""}, 72=>{"hrs"=>""}, 112=>{"hrs"=>""}, 32=>{"hrs"=>""}, 80=>{"hrs"=>""}, 120=>{"hrs"=>""}, 60=>{"hrs"=>""}, 20=>{"hrs"=>""}, 68=>{"hrs"=>""}, 108=>{"hrs"=>""}, 28=>{"hrs"=>""}, 76=>{"hrs"=>""}, 116=>{"hrs"=>""}, 63=>{"hrs"=>""}, 23=>{"hrs"=>""}, 71=>{"hrs"=>""}, 111=>{"hrs"=>""}, 31=>{"hrs"=>""}, 79=>{"hrs"=>""}, 119=>{"hrs"=>""}, 58=>{"hrs"=>""}, 18=>{"hrs"=>""}, 66=>{"hrs"=>""}, 106=>{"hrs"=>""}, 26=>{"hrs"=>""}, 74=>{"hrs"=>""}, 114=>{"hrs"=>""}, 65=>{"hrs"=>""}, 25=>{"hrs"=>""}, 73=>{"hrs"=>""}, 113=>{"hrs"=>""}, 33=>{"hrs"=>""}, 81=>{"hrs"=>""}, 121=>{"hrs"=>""}}

update_hash keys= [59, 19, 67, 107, 27, 75, 115, 64, 24, 72, 112, 32, 80, 120, 60, 20, 68, 108, 28, 76, 116, 63, 23, 71, 111, 31, 79, 119, 58, 18, 66, 106, 26, 74, 114, 65, 25, 73, 113, 33, 81, 121]

update_hash values = [{"hrs"=>"5"}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>"6"}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>"8"}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}, {"hrs"=>""}]

i @ complete loss here. know make work iterating through each key/value pair 1 one, seems pretty inefficient. appreciated.

the solution above question define acceptable params in controller shown below:

  def schedule_params     @update_hash.require(:employee_schedule).permit(:hrs)   end 

with method, code above works without errors.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -