I have an array of objects on my frontend that I want to pass to my rails controller.
The array of object I'm passing to my controller looks like this:
[
{id: 1, position: 1},
{id: 2, position: 2}
]
In my controller, I'm trying to do something like this:
def map
params[:items].each do |item|
todo = @user.todos.new(
item_id: item.id,
item_position: item.position
)
todo.save!
end
end
I tried JSON.stringify on my array and then sending it to my controller but everything is a string so a lot of my methods are not working.
What is the correct way to pass in an array of objects to a rails controller?
JSON.parsein rails, I'm getting an errorundefined method 'id' for {:id=>1}:Hash