I'm fairly new to Rails but I have a situation where a user can create a vacancy and select modules for that vacancy by dragging en dropping modules. Everytime something has changed (a module has been added/removes to the vacancy of the order has changed) I send a javascript object to the rails controller through AJAX and I want to extract the values from this object and story them in my DB.
My object will look like this:
addedModules = {
module: [
{module_id: '1', name: 'first-module', width: '3', height: '1', position: '1'},
{module_id: '5', name: 'fifth-module', width: '1', height: '1', position: '2'},
{module_id: '3', name: 'third-module', width: '4', height: '1', position: '3'},
]
};
In my controller I would like to go through every module and extract their module_id, name, etc.
AJAX block:
$.ajax({
type: "POST",
url: "../../../vacancies/" + <%= params[:vacancy_id] %> + "/update_with_modules",
data: "addedModules=" + addedModules
}).done(function (response) {
console.log(response);
});
Is there a way to do so or is there a better solution?
params[:addedModules], but if I useparams[:addedModules][0]or something like that I get "[" and withparams[:addedModules][1]I get "o" so it's getting the word "object" and not the values of the object.