3

I've got the following jQuery variable:

var numbers = ["1", "2", "3"]

I want to submit a form with these numbers so that my params variable looks like this in the controller:

{ 
  "evaluation" =>
  {
     "batch_subject_ids" => ["1", "2", "3"]
  }
}

I am creating this array on the fly when I click a button

jQuery('<input>').attr({
  type: 'hidden',
  id: 'batch_subject_ids',
  name: 'evaluation[batch_subject_ids][]',
  value: batch_subject_ids
}).appendTo('form');

In the controller action, I receive the following params:

{ 
  "evaluation" =>
  {
     "batch_subject_ids" => ["1,2,3"]
  }
}

I can parse and replace the array, but I was wondering if I could send it from the client with the format I want without having to do that. How can I accomplish this? Thank you

1 Answer 1

1

have a read through http://guides.rubyonrails.org/action_controller_overview.html#hash-and-array-parameters

You need to send separate values of batch_subject_ids[] = 1, batch_subject_ids[] = 2 etc. for this to be turned into an array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.