Here is the .ajax call. The variable questions is a JSON object:
Object {question_1: "3", question_2: "6", question_3: "9", question_4: "15", question_5: "12"}
$.ajax({
type: "POST",
url: "/save",
data: questions,
dataType: 'json',
contentType: 'application/json',
success: function (data) {
alert('success');
}
});
My ruby contorller.
def save
# How do I access the data object?
end
Do I just do a params[:data] or params[:questions] ?
Thanks and while I found other questions similar to this, none mentioned what the actual parameter name is called.
It’s whatever you’ve made the questions variable. If you’ve included a root object
It’ll be accessible at
params[:question]Otherwise the attributes will be included in the root of the
paramshash along with anything Rails adds and the URL attributes.By the by, I would expect the data in a variable called
questionsto look something like this: