I’m trying to create multiple objects through Controller with a single call. However I’m getting ActiveModel::ForbiddenAttributesError
:
Params:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"JOBnvYmshIefa2LeKkaMeaN+dHYq+VZlUPmmi4++I3Y=", "student_ids"=>"1,2", "message"=>{"content"=>"{{first_name}}"}, "commit"=>"Create Message"}
My actions:
def create
# Build arrays of data
arr = Array.new
params[:student_ids].split(",").each do |id|
h = params[:message].merge("student_id" => id, "center_id" => current_center.id)
arr << h
end
new_params = ActionController::Parameters.new(data: arr)
new_params.permit(data: [:content, :student_id, :center_id])
if Message.create(new_params)
redirect_to new_message_path, notice: 'Message was successfully created.'
else
render action: 'new'
end
end
Any idea on how to solve it?