Convert javascript array to a ruby array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    Convert javascript array to a ruby array

    Hey can anyone help me convert a javascript array into a ruby array.
    Ive been struggling with this since friday to no avail. This is the
    function with the ajax.request call that is supposed to convert the
    array using JSON, but I keep getting a 422(Unprocessab le Entity)
    error. Im not sure what is wrong.

    function test()
    {
    for(i=1;i<22;i+ +){
    if (document.getEl ementById(i+'d' ).className ==
    "selected") {
    myArray.push(i) ;
    }
    }

    new Ajax.Request('/appointments/array/',
    {method:'put',p ostBody:"'data= '+myArray.toJSO N"});

    }

    Thanks for any input!
  • SAM

    #2
    Re: Convert javascript array to a ruby array

    David a écrit :
    Hey can anyone help me convert a javascript array into a ruby array.
    Ive been struggling with this since friday to no avail. This is the
    function with the ajax.request call that is supposed to convert the
    array using JSON, but I keep getting a 422(Unprocessab le Entity)
    error. Im not sure what is wrong.
    >
    function test()
    {
    var myArray = [];
    for(i=1;i<22;i+ +){
    if (document.getEl ementById(i+'d' ).className ==
    could be better with :
    if (document.getEl ementById('d'+i ).className ==
    no ?
    "selected") {
    myArray.push(i) ;
    }
    }
    alert('myArray = '+myArray.join( ' - '));
    alert('myArray. toJSON = '+myArray.toJSO N());

    new Ajax.Request('/appointments/array/',
    {method:'put',p ostBody:"'data= '+myArray.toJSO N"});
    >
    }
    >
    Thanks for any input!

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Convert javascript array to a ruby array

      David wrote:
      Hey can anyone help me convert a javascript array into a ruby array.
      If you told us what a "ruby array" is, the chances for that would increase
      considerably.
      [...] This is the
      function with the ajax.request call that is supposed to convert the
      array using JSON, but I keep getting a 422(Unprocessab le Entity)
      error.
      Useless information, without knowing what was going to be processed where
      and how.
      Im not sure what is wrong.
      Neither can anyone else, unless you told us ...
      function test()
      {
      for(i=1;i<22;i+ +){
      if (document.getEl ementById(i+'d' ).className ==
      "selected") {
      myArray.push(i) ;
      what `myArray' is, ...
      }
      }
      >
      new Ajax.Request('/appointments/array/',
      {method:'put',p ostBody:"'data= '+myArray.toJSO N"});
      what `Ajax.Request' is.

      BTW: You "forgot" to declare `i' a variable.
      }
      >
      Thanks for any input!
      Likewise.

      <http//jibbering.com/faq/>


      PointedEars
      --
      Anyone who slaps a 'this page is best viewed with Browser X' label on
      a Web page appears to be yearning for the bad old days, before the Web,
      when you had very little chance of reading a document written on another
      computer, another word processor, or another network. -- Tim Berners-Lee

      Comment

      Working...