Я получаю следующее сообщение об ошибке при попытке обновить модель Rails с помощью метода обновления ActiveModel:ActiveModel :: ForbiddenAttributesError в Rails 4?
ActiveModel::ForbiddenAttributesError
Я осведомлен о сильных параметрах требования в Rails 4 на ссылку ниже, но как белый список params в моем случае - массив хэшей? Я не могу понять документацию.
http://guides.rubyonrails.org/action_controller_overview.html#strong-parameters
Вот в JSon Params, что я пытаюсь процесса: действие
{
id: 1,
month: 'April',
measurements: [
{ id: 1, name: 'PT', location_1: '1.1', location_2: '1.2' },
{ id: 1, name: 'OT', location_1: '1.1', location_2: '1.2' },
.
.
]
}
Контроллер:
def update
#Trying to update all measurements associated with this parent object
#params.permit(measurements: [{ :name, :location_1, :location_2 } ])
#This attempt causes a syntax error
measurements = params[:measurements]
measurements.each do |measurement|
current_measurement = Measurement.find(measurement[:id])
new_measurement = measurement.except(:id)
current_measurement.update(new_measurement)
end
.
.
end
try: 'params.permit (: month, measurement_attributes: [: id,: name,: location_1,: location_2])' (он может быть сингулярным, а не множественным - не помню, так что попробуйте это тоже) –
см. Http: //stackoverflow.com/a/25211289/1377943 –
У меня такая же ошибка. Любые другие идеи? Благодаря! –