Sylar Sylar - 1 year ago 71
Ruby Question

Split on second comma in ruby

Apologies for the "not so great questions". This happens when your eyes are closed but your brain keeps thinking about code.

This bit puzzles me. I want to split a string on a comma to make it an array, OR..., if I can send to my controller the array then perfect but anything I do never seem to work so what may work is to split on the second comma in a string.

I have a state array that looks like this:
enter image description here

So when I use

I get a handle error for
because it splits on the first comma when the code itself it correct. A stupid question, can you split on the second comma in ruby?

The array is like:

My input looks like this and I have tried many variations with

<input type="hidden" name="file" value={this.state.files} />

I've used
to get the array.

Answer Source

You could also serialize the files array in a different manner before sending to Rails.

What does the code that sends files look like?

If anything, can you join it like this, with some unique separator?

makeRequest({ file: this.state.files.join('---') });

And then split with that in Ruby