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(Unprocessable Entity) error. Im not sure what is wrong. function test() { for(i=1;i<22;i++){ if (document.getElementById(i+''d'').className ="selected"){ myArray.push(i); } } new Ajax.Request(''/appointments/array/'', {method:''get'',postBody:"''data=''+myArray.toJSON"}); } Thanks for any input! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry, that ajax.request method should be a put, so: new Ajax.Request(''/appointments/array/'', {method:''post'',postBody:"''data=''+myArray.toJSON"}); On Sep 8, 2:52 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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(Unprocessable Entity) > error. Im not sure what is wrong. > > function test() > { > for(i=1;i<22;i++){ > if (document.getElementById(i+''d'').className => "selected"){ > myArray.push(i); > } > } > > new Ajax.Request(''/appointments/array/'', > {method:''get'',postBody:"''data=''+myArray.toJSON"}); > > } > > Thanks for any input!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 Sep 2008, at 22:54, David wrote:> > Sorry, that ajax.request method should be a put, so: > > new Ajax.Request(''/appointments/array/'', > {method:''post'',postBody:"''data=''+myArray.toJSON"}); >If you''re just posting json then you shouldn''t that data= (and you look like you''re writing a link_to_remote :with option - right now you''re posting the string "''data=''+myArray.toJSON") something like postBody: Object.toJSON(myArray) is more like it. You might also need to set the content-type header appropriately. Fred> On Sep 8, 2:52 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> 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(Unprocessable Entity) >> error. Im not sure what is wrong. >> >> function test() >> { >> for(i=1;i<22;i++){ >> if (document.getElementById(i+''d'').className =>> "selected"){ >> myArray.push(i); >> } >> } >> >> new Ajax.Request(''/appointments/array/'', >> {method:''get'',postBody:"''data=''+myArray.toJSON"}); >> >> } >> >> Thanks for any input! > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yea, I am trying to just use the link_to_remote helper now, but aside from converting the array and using JSON, I can''t even get the link_to_remote to route now. I am using: <%= link_to_remote ''Click me'', :url => {:action => "update"}, :with => ''test'' %> and the only action that works successfully is the new action, so <%= link_to_remote ''Click me'', :url => {:action => "new"}, :with => ''test'' %> routes successfully, but this is not what i want. I get this error in firebug: POST http://localhost:3000/appointments/update500 241ms. Do you have any idea why this is happening? On Sep 8, 6:30 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 8 Sep 2008, at 22:54, David wrote: > > > > > Sorry, that ajax.request method should be a put, so: > > > new Ajax.Request(''/appointments/array/'', > > {method:''post'',postBody:"''data=''+myArray.toJSON"}); > > If you''re just posting json then you shouldn''t that data= (and you > look like you''re writing a link_to_remote :with option - right now > you''re posting the string "''data=''+myArray.toJSON") > > something like > > postBody: Object.toJSON(myArray) > > is more like it. You might also need to set the content-type header > appropriately. > > Fred > > > On Sep 8, 2:52 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> 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(Unprocessable Entity) > >> error. Im not sure what is wrong. > > >> function test() > >> { > >> for(i=1;i<22;i++){ > >> if (document.getElementById(i+''d'').className => >> "selected"){ > >> myArray.push(i); > >> } > >> } > > >> new Ajax.Request(''/appointments/array/'', > >> {method:''get'',postBody:"''data=''+myArray.toJSON"}); > > >> } > > >> Thanks for any input!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 9 Sep 2008, at 02:42, David wrote:> > Yea, I am trying to just use the link_to_remote helper now, but aside > from converting the array and using JSON, I can''t even get the > link_to_remote to route now. I am using: > > <%= link_to_remote ''Click me'', :url => {:action => "update"}, :with > => ''test'' %> > > and the only action that works successfully is the new action, so > > <%= link_to_remote ''Click me'', :url => {:action => "new"}, :with => > ''test'' %> > > routes successfully, but this is not what i want. I get this error in > firebug: > > POST http://localhost:3000/appointments/update500 241ms. >I assume that''s telling you that the server returned a 500 error, which means check your logs. Fred> Do you have any idea why this is happening? > > On Sep 8, 6:30 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 8 Sep 2008, at 22:54, David wrote: >> >> >> >>> Sorry, that ajax.request method should be a put, so: >> >>> new Ajax.Request(''/appointments/array/'', >>> {method:''post'',postBody:"''data=''+myArray.toJSON"}); >> >> If you''re just posting json then you shouldn''t that data= (and you >> look like you''re writing a link_to_remote :with option - right now >> you''re posting the string "''data=''+myArray.toJSON") >> >> something like >> >> postBody: Object.toJSON(myArray) >> >> is more like it. You might also need to set the content-type header >> appropriately. >> >> Fred >> >>> On Sep 8, 2:52 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> 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(Unprocessable Entity) >>>> error. Im not sure what is wrong. >> >>>> function test() >>>> { >>>> for(i=1;i<22;i++){ >>>> if (document.getElementById(i+''d'').className =>>>> "selected"){ >>>> myArray.push(i); >>>> } >>>> } >> >>>> new Ajax.Request(''/appointments/array/'', >>>> {method:''get'',postBody:"''data=''+myArray.toJSON"}); >> >>>> } >> >>>> Thanks for any input! > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
okay, thanks for the heads up. The error says, TypeError (exception object expected). Not sure what this means, do you have any idea? On Sep 8, 6:45 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 9 Sep 2008, at 02:42, David wrote: > > > > > > > Yea, I am trying to just use the link_to_remote helper now, but aside > > from converting the array and using JSON, I can''t even get the > > link_to_remote to route now. I am using: > > > <%= link_to_remote ''Click me'', :url => {:action => "update"}, :with > > => ''test'' %> > > > and the only action that works successfully is the new action, so > > > <%= link_to_remote ''Click me'', :url => {:action => "new"}, :with => > > ''test'' %> > > > routes successfully, but this is not what i want. I get this error in > > firebug: > > > POSThttp://localhost:3000/appointments/update500241ms. > > I assume that''s telling you that the server returned a 500 error, > which means check your logs. > > Fred > > > Do you have any idea why this is happening? > > > On Sep 8, 6:30 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 8 Sep 2008, at 22:54, David wrote: > > >>> Sorry, that ajax.request method should be a put, so: > > >>> new Ajax.Request(''/appointments/array/'', > >>> {method:''post'',postBody:"''data=''+myArray.toJSON"}); > > >> If you''re just posting json then you shouldn''t that data= (and you > >> look like you''re writing a link_to_remote :with option - right now > >> you''re posting the string "''data=''+myArray.toJSON") > > >> something like > > >> postBody: Object.toJSON(myArray) > > >> is more like it. You might also need to set the content-type header > >> appropriately. > > >> Fred > > >>> On Sep 8, 2:52 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>>> 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(Unprocessable Entity) > >>>> error. Im not sure what is wrong. > > >>>> function test() > >>>> { > >>>> for(i=1;i<22;i++){ > >>>> if (document.getElementById(i+''d'').className => >>>> "selected"){ > >>>> myArray.push(i); > >>>> } > >>>> } > > >>>> new Ajax.Request(''/appointments/array/'', > >>>> {method:''get'',postBody:"''data=''+myArray.toJSON"}); > > >>>> } > > >>>> Thanks for any input!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 9, 6:22 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> okay, thanks for the heads up. The error says, TypeError (exception > object expected). Not sure what this means, do you have any idea? >Usually it means you tried to raise something that isn''t an exception, but without a backtrace or seeing the line that cause this error it''s hard to say. Fred> On Sep 8, 6:45 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On 9 Sep 2008, at 02:42, David wrote: > > > > Yea, I am trying to just use the link_to_remote helper now, but aside > > > from converting the array and using JSON, I can''t even get the > > > link_to_remote to route now. I am using: > > > > <%= link_to_remote ''Click me'', :url => {:action => "update"}, :with > > > => ''test'' %> > > > > and the only action that works successfully is the new action, so > > > > <%= link_to_remote ''Click me'', :url => {:action => "new"}, :with => > > > ''test'' %> > > > > routes successfully, but this is not what i want. I get this error in > > > firebug: > > > > POSThttp://localhost:3000/appointments/update500241ms. > > > I assume that''s telling you that the server returned a 500 error, > > which means check your logs. > > > Fred > > > > Do you have any idea why this is happening? > > > > On Sep 8, 6:30 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > >> On 8 Sep 2008, at 22:54, David wrote: > > > >>> Sorry, that ajax.request method should be a put, so: > > > >>> new Ajax.Request(''/appointments/array/'', > > >>> {method:''post'',postBody:"''data=''+myArray.toJSON"}); > > > >> If you''re just posting json then you shouldn''t that data= (and you > > >> look like you''re writing a link_to_remote :with option - right now > > >> you''re posting the string "''data=''+myArray.toJSON") > > > >> something like > > > >> postBody: Object.toJSON(myArray) > > > >> is more like it. You might also need to set the content-type header > > >> appropriately. > > > >> Fred > > > >>> On Sep 8, 2:52 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>>> 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(Unprocessable Entity) > > >>>> error. Im not sure what is wrong. > > > >>>> function test() > > >>>> { > > >>>> for(i=1;i<22;i++){ > > >>>> if (document.getElementById(i+''d'').className => > >>>> "selected"){ > > >>>> myArray.push(i); > > >>>> } > > >>>> } > > > >>>> new Ajax.Request(''/appointments/array/'', > > >>>> {method:''get'',postBody:"''data=''+myArray.toJSON"}); > > > >>>> } > > > >>>> Thanks for any input!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This is the line that caused the error: <%= link_to_remote ''Click me'', :url => {:controller => "appointments", :action => "array"}, :with => "test"%>. These are the lines that follow the error: TypeError (exception object expected): /app/controllers/appointments_controller.rb:72:in `raise'' /app/controllers/appointments_controller.rb:72:in `array'' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'' C:/InstantRails-2.0-win/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'' Not sure if this is helpful at all. Thanks for your help. On Sep 9, 12:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 9, 6:22 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> okay, thanks for the heads up. The error says, TypeError (exception > > object expected). Not sure what this means, do you have any idea? > > Usually it means you tried to raise something that isn''t an exception, > but without a backtrace or seeing the line that cause this error it''s > hard to say. > > Fred > > > On Sep 8, 6:45 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On 9 Sep 2008, at 02:42, David wrote: > > > > > Yea, I am trying to just use the link_to_remote helper now, but aside > > > > from converting the array and using JSON, I can''t even get the > > > > link_to_remote to route now. I am using: > > > > > <%= link_to_remote ''Click me'', :url => {:action => "update"}, :with > > > > => ''test'' %> > > > > > and the only action that works successfully is the new action, so > > > > > <%= link_to_remote ''Click me'', :url => {:action => "new"}, :with => > > > > ''test'' %> > > > > > routes successfully, but this is not what i want. I get this error in > > > > firebug: > > > > > POSThttp://localhost:3000/appointments/update500241ms. > > > > I assume that''s telling you that the server returned a 500 error, > > > which means check your logs. > > > > Fred > > > > > Do you have any idea why this is happening? > > > > > On Sep 8, 6:30 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > wrote: > > > >> On 8 Sep 2008, at 22:54, David wrote: > > > > >>> Sorry, that ajax.request method should be a put, so: > > > > >>> new Ajax.Request(''/appointments/array/'', > > > >>> {method:''post'',postBody:"''data=''+myArray.toJSON"}); > > > > >> If you''re just posting json then you shouldn''t that data= (and you > > > >> look like you''re writing a link_to_remote :with option - right now > > > >> you''re posting the string "''data=''+myArray.toJSON") > > > > >> something like > > > > >> postBody: Object.toJSON(myArray) > > > > >> is more like it. You might also need to set the content-type header > > > >> appropriately. > > > > >> Fred > > > > >>> On Sep 8, 2:52 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >>>> 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(Unprocessable Entity) > > > >>>> error. Im not sure what is wrong. > > > > >>>> function test() > > > >>>> { > > > >>>> for(i=1;i<22;i++){ > > > >>>> if (document.getElementById(i+''d'').className => > > >>>> "selected"){ > > > >>>> myArray.push(i); > > > >>>> } > > > >>>> } > > > > >>>> new Ajax.Request(''/appointments/array/'', > > > >>>> {method:''get'',postBody:"''data=''+myArray.toJSON"}); > > > > >>>> } > > > > >>>> Thanks for any input!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 9, 9:03 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This is the line that caused the error: <%= link_to_remote ''Click > me'', :url => {:controller => "appointments", :action => > "array"}, :with => "test"%>. These are the lines that follow theNo, that line didn''t cause the error. That piece of code worked just fine and generated a link you clicked on, and processing that request caused the error> error: > TypeError (exception object expected): > /app/controllers/appointments_controller.rb:72:in `raise'' > /app/controllers/appointments_controller.rb:72:in `array''This is the line causing the error (and it looks like you''re calling raise yourself) Fred> C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'' > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > actionpack-2.0.2/lib/action_controller/base.rb:1158:in > `perform_action_without_filters'' > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > actionpack-2.0.2/lib/action_controller/filters.rb:697:in > `call_filters'' > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > actionpack-2.0.2/lib/action_controller/filters.rb:689:in > `perform_action_without_benchmark'' > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in > `perform_action_without_rescue'' > C:/InstantRails-2.0-win/ruby/lib/ruby/1.8/benchmark.rb:293:in > `measure'' > > Not sure if this is helpful at all. Thanks for your help. > > On Sep 9, 12:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Sep 9, 6:22 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> okay, thanks for the heads up. The error says, TypeError (exception > > > object expected). Not sure what this means, do you have any idea? > > > Usually it means you tried to raise something that isn''t an exception, > > but without a backtrace or seeing the line that cause this error it''s > > hard to say. > > > Fred > > > > On Sep 8, 6:45 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > On 9 Sep 2008, at 02:42, David wrote: > > > > > > Yea, I am trying to just use the link_to_remote helper now, but aside > > > > > from converting the array and using JSON, I can''t even get the > > > > > link_to_remote to route now. I am using: > > > > > > <%= link_to_remote ''Click me'', :url => {:action => "update"}, :with > > > > > => ''test'' %> > > > > > > and the only action that works successfully is the new action, so > > > > > > <%= link_to_remote ''Click me'', :url => {:action => "new"}, :with => > > > > > ''test'' %> > > > > > > routes successfully, but this is not what i want. I get this error in > > > > > firebug: > > > > > > POSThttp://localhost:3000/appointments/update500241ms. > > > > > I assume that''s telling you that the server returned a 500 error, > > > > which means check your logs. > > > > > Fred > > > > > > Do you have any idea why this is happening? > > > > > > On Sep 8, 6:30 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > wrote: > > > > >> On 8 Sep 2008, at 22:54, David wrote: > > > > > >>> Sorry, that ajax.request method should be a put, so: > > > > > >>> new Ajax.Request(''/appointments/array/'', > > > > >>> {method:''post'',postBody:"''data=''+myArray.toJSON"}); > > > > > >> If you''re just posting json then you shouldn''t that data= (and you > > > > >> look like you''re writing a link_to_remote :with option - right now > > > > >> you''re posting the string "''data=''+myArray.toJSON") > > > > > >> something like > > > > > >> postBody: Object.toJSON(myArray) > > > > > >> is more like it. You might also need to set the content-type header > > > > >> appropriately. > > > > > >> Fred > > > > > >>> On Sep 8, 2:52 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > >>>> 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(Unprocessable Entity) > > > > >>>> error. Im not sure what is wrong. > > > > > >>>> function test() > > > > >>>> { > > > > >>>> for(i=1;i<22;i++){ > > > > >>>> if (document.getElementById(i+''d'').className => > > > >>>> "selected"){ > > > > >>>> myArray.push(i); > > > > >>>> } > > > > >>>> } > > > > > >>>> new Ajax.Request(''/appointments/array/'', > > > > >>>> {method:''get'',postBody:"''data=''+myArray.toJSON"}); > > > > > >>>> } > > > > > >>>> Thanks for any input!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yea, you were right, its been a long day....but i have finally figured it out. Thanks for your help. For anyone who is trying to convert a javascript array to a ruby array and pass the array to the controller you can follow this advice: create a javascript function that returns the array with the toJSON() function, so like this: function example(){ myArray = new Array(); ....... return myArray.toJSON() } you can then send this converted array to an action using the link_to_remote ajax helper by calling your javascript function within the :with parameter like so: <%= link_to_remote ''Click me'', :url => {:action => "array"}, :with => "''data=''+test()", :update => ''testing''%> Your array will then be accessible in params[:data] in you action (array in this case) On Sep 9, 1:07 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 9, 9:03 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > This is the line that caused the error: <%= link_to_remote ''Click > > me'', :url => {:controller => "appointments", :action => > > "array"}, :with => "test"%>. These are the lines that follow the > > No, that line didn''t cause the error. That piece of code worked just > fine and generated a link you clicked on, and processing that request > caused the error > > > error: > > TypeError (exception object expected): > > /app/controllers/appointments_controller.rb:72:in `raise'' > > /app/controllers/appointments_controller.rb:72:in `array'' > > This is the line causing the error (and it looks like you''re calling > raise yourself) > > Fred > > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'' > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > actionpack-2.0.2/lib/action_controller/base.rb:1158:in > > `perform_action_without_filters'' > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > actionpack-2.0.2/lib/action_controller/filters.rb:697:in > > `call_filters'' > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > actionpack-2.0.2/lib/action_controller/filters.rb:689:in > > `perform_action_without_benchmark'' > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in > > `perform_action_without_rescue'' > > C:/InstantRails-2.0-win/ruby/lib/ruby/1.8/benchmark.rb:293:in > > `measure'' > > > Not sure if this is helpful at all. Thanks for your help. > > > On Sep 9, 12:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On Sep 9, 6:22 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> okay, thanks for the heads up. The error says, TypeError (exception > > > > object expected). Not sure what this means, do you have any idea? > > > > Usually it means you tried to raise something that isn''t an exception, > > > but without a backtrace or seeing the line that cause this error it''s > > > hard to say. > > > > Fred > > > > > On Sep 8, 6:45 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > wrote: > > > > > > On 9 Sep 2008, at 02:42, David wrote: > > > > > > > Yea, I am trying to just use the link_to_remote helper now, but aside > > > > > > from converting the array and using JSON, I can''t even get the > > > > > > link_to_remote to route now. I am using: > > > > > > > <%= link_to_remote ''Click me'', :url => {:action => "update"}, :with > > > > > > => ''test'' %> > > > > > > > and the only action that works successfully is the new action, so > > > > > > > <%= link_to_remote ''Click me'', :url => {:action => "new"}, :with => > > > > > > ''test'' %> > > > > > > > routes successfully, but this is not what i want. I get this error in > > > > > > firebug: > > > > > > > POSThttp://localhost:3000/appointments/update500241ms. > > > > > > I assume that''s telling you that the server returned a 500 error, > > > > > which means check your logs. > > > > > > Fred > > > > > > > Do you have any idea why this is happening? > > > > > > > On Sep 8, 6:30 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > > wrote: > > > > > >> On 8 Sep 2008, at 22:54, David wrote: > > > > > > >>> Sorry, that ajax.request method should be a put, so: > > > > > > >>> new Ajax.Request(''/appointments/array/'', > > > > > >>> {method:''post'',postBody:"''data=''+myArray.toJSON"}); > > > > > > >> If you''re just posting json then you shouldn''t that data= (and you > > > > > >> look like you''re writing a link_to_remote :with option - right now > > > > > >> you''re posting the string "''data=''+myArray.toJSON") > > > > > > >> something like > > > > > > >> postBody: Object.toJSON(myArray) > > > > > > >> is more like it. You might also need to set the content-type header > > > > > >> appropriately. > > > > > > >> Fred > > > > > > >>> On Sep 8, 2:52 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > >>>> 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(Unprocessable Entity) > > > > > >>>> error. Im not sure what is wrong. > > > > > > >>>> function test() > > > > > >>>> { > > > > > >>>> for(i=1;i<22;i++){ > > > > > >>>> if (document.getElementById(i+''d'').className => > > > > >>>> "selected"){ > > > > > >>>> myArray.push(i); > > > > > >>>> } > > > > > >>>> } > > > > > > >>>> new Ajax.Request(''/appointments/array/'', > > > > > >>>> {method:''get'',postBody:"''data=''+myArray.toJSON"}); > > > > > > >>>> } > > > > > > >>>> Thanks for any input!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
So it turns out the call myArray.toJSON() only converts the javascript array myArray to a string. I have implemented a work around parse to convert the string into an array, but i was wondering if anyone knows of a JSON method to convert directly to a ruby array. Maybe this would be faster? On Sep 9, 2:40 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yea, you were right, its been a long day....but i have finally figured > it out. Thanks for your help. For anyone who is trying to convert a > javascript array to a ruby array and pass the array to the controller > you can follow this advice: > create a javascript function that returns the array with the toJSON() > function, so like this: > function example(){ > myArray = new Array(); > ....... > return myArray.toJSON() > > } > > you can then send this converted array to an action using the > link_to_remote ajax helper by calling your javascript function within > the :with parameter like so: > > <%= link_to_remote ''Click me'', :url => {:action => "array"}, :with => > "''data=''+test()", :update => ''testing''%> > > Your array will then be accessible in params[:data] in you action > (array in this case) > > On Sep 9, 1:07 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Sep 9, 9:03 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > This is the line that caused the error: <%= link_to_remote ''Click > > > me'', :url => {:controller => "appointments", :action => > > > "array"}, :with => "test"%>. These are the lines that follow the > > > No, that line didn''t cause the error. That piece of code worked just > > fine and generated a link you clicked on, and processing that request > > caused the error > > > > error: > > > TypeError (exception object expected): > > > /app/controllers/appointments_controller.rb:72:in `raise'' > > > /app/controllers/appointments_controller.rb:72:in `array'' > > > This is the line causing the error (and it looks like you''re calling > > raise yourself) > > > Fred > > > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > > actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'' > > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > > actionpack-2.0.2/lib/action_controller/base.rb:1158:in > > > `perform_action_without_filters'' > > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > > actionpack-2.0.2/lib/action_controller/filters.rb:697:in > > > `call_filters'' > > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > > actionpack-2.0.2/lib/action_controller/filters.rb:689:in > > > `perform_action_without_benchmark'' > > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > > actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in > > > `perform_action_without_rescue'' > > > C:/InstantRails-2.0-win/ruby/lib/ruby/1.8/benchmark.rb:293:in > > > `measure'' > > > > Not sure if this is helpful at all. Thanks for your help. > > > > On Sep 9, 12:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > On Sep 9, 6:22 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> okay, thanks for the heads up. The error says, TypeError (exception > > > > > object expected). Not sure what this means, do you have any idea? > > > > > Usually it means you tried to raise something that isn''t an exception, > > > > but without a backtrace or seeing the line that cause this error it''s > > > > hard to say. > > > > > Fred > > > > > > On Sep 8, 6:45 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > > wrote: > > > > > > > On 9 Sep 2008, at 02:42, David wrote: > > > > > > > > Yea, I am trying to just use the link_to_remote helper now, but aside > > > > > > > from converting the array and using JSON, I can''t even get the > > > > > > > link_to_remote to route now. I am using: > > > > > > > > <%= link_to_remote ''Click me'', :url => {:action => "update"}, :with > > > > > > > => ''test'' %> > > > > > > > > and the only action that works successfully is the new action, so > > > > > > > > <%= link_to_remote ''Click me'', :url => {:action => "new"}, :with => > > > > > > > ''test'' %> > > > > > > > > routes successfully, but this is not what i want. I get this error in > > > > > > > firebug: > > > > > > > > POSThttp://localhost:3000/appointments/update500241ms. > > > > > > > I assume that''s telling you that the server returned a 500 error, > > > > > > which means check your logs. > > > > > > > Fred > > > > > > > > Do you have any idea why this is happening? > > > > > > > > On Sep 8, 6:30 pm, Frederick Cheung <frederick.che...@gmail.com> > > > > > > > wrote: > > > > > > >> On 8 Sep 2008, at 22:54, David wrote: > > > > > > > >>> Sorry, that ajax.request method should be a put, so: > > > > > > > >>> new Ajax.Request(''/appointments/array/'', > > > > > > >>> {method:''post'',postBody:"''data=''+myArray.toJSON"}); > > > > > > > >> If you''re just posting json then you shouldn''t that data= (and you > > > > > > >> look like you''re writing a link_to_remote :with option - right now > > > > > > >> you''re posting the string "''data=''+myArray.toJSON") > > > > > > > >> something like > > > > > > > >> postBody: Object.toJSON(myArray) > > > > > > > >> is more like it. You might also need to set the content-type header > > > > > > >> appropriately. > > > > > > > >> Fred > > > > > > > >>> On Sep 8, 2:52 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > >>>> 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(Unprocessable Entity) > > > > > > >>>> error. Im not sure what is wrong. > > > > > > > >>>> function test() > > > > > > >>>> { > > > > > > >>>> for(i=1;i<22;i++){ > > > > > > >>>> if (document.getElementById(i+''d'').className => > > > > > >>>> "selected"){ > > > > > > >>>> myArray.push(i); > > > > > > >>>> } > > > > > > >>>> } > > > > > > > >>>> new Ajax.Request(''/appointments/array/'', > > > > > > >>>> {method:''get'',postBody:"''data=''+myArray.toJSON"}); > > > > > > > >>>> } > > > > > > > >>>> Thanks for any input!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I may be wrong, but since JS is a client side language and Ruby is a server side language, won''t all of the ruby code have been parsed before the JS array is ever even created? -- Josh David wrote:> So it turns out the call myArray.toJSON() only converts the javascript > array myArray to a string. I have implemented a work around parse to > convert the string into an array, but i was wondering if anyone knows > of a JSON method to convert directly to a ruby array. Maybe this > would be faster?-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 9, 10:38 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So it turns out the call myArray.toJSON() only converts the javascript > array myArray to a string. I have implemented a work around parse to > convert the string into an array, but i was wondering if anyone knows > of a JSON method to convert directly to a ruby array. Maybe this > would be faster?What would that even mean? Everything the browser sends to the server is serialized in some format - there''s no escaping that. Fred> > On Sep 9, 2:40 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Yea, you were right, its been a long day....but i have finally figured > > it out. Thanks for your help. For anyone who is trying to convert a > > javascript array to a ruby array and pass the array to the controller > > you can follow this advice: > > create a javascript function that returns the array with the toJSON() > > function, so like this: > > function example(){ > > myArray = new Array(); > > ....... > > return myArray.toJSON() > > > } > > > you can then send this converted array to an action using the > > link_to_remote ajax helper by calling your javascript function within > > the :with parameter like so: > > > <%= link_to_remote ''Click me'', :url => {:action => "array"}, :with => > > "''data=''+test()", :update => ''testing''%> > > > Your array will then be accessible in params[:data] in you action > > (array in this case) > > > On Sep 9, 1:07 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On Sep 9, 9:03 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > This is the line that caused the error: <%= link_to_remote ''Click > > > > me'', :url => {:controller => "appointments", :action => > > > > "array"}, :with => "test"%>. These are the lines that follow the > > > > No, that line didn''t cause the error. That piece of code worked just > > > fine and generated a link you clicked on, and processing that request > > > caused the error > > > > > error: > > > > TypeError (exception object expected): > > > > /app/controllers/appointments_controller.rb:72:in `raise'' > > > > /app/controllers/appointments_controller.rb:72:in `array'' > > > > This is the line causing the error (and it looks like you''re calling > > > raise yourself) > > > > Fred > > > > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > > > actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'' > > > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > > > actionpack-2.0.2/lib/action_controller/base.rb:1158:in > > > > `perform_action_without_filters'' > > > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > > > actionpack-2.0.2/lib/action_controller/filters.rb:697:in > > > > `call_filters'' > > > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > > > actionpack-2.0.2/lib/action_controller/filters.rb:689:in > > > > `perform_action_without_benchmark'' > > > > C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/ > > > > actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in > > > > `perform_action_without_rescue'' > > > > C:/InstantRails-2.0-win/ruby/lib/ruby/1.8/benchmark.rb:293:in > > > > `measure'' > > > > > Not sure if this is helpful at all. Thanks for your help. > > > > > On Sep 9, 12:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > wrote: > > > > > > On Sep 9, 6:22 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> okay, thanks for the heads up. The error says, TypeError (exception > > > > > > object expected). Not sure what this means, do you have any idea? > > > > > > Usually it means you tried to raise something that isn''t an exception, > > > > > but without a backtrace or seeing the line that cause this error it''s > > > > > hard to say. > > > > > > Fred > > > > > > > On Sep 8, 6:45 pm, Frederick Cheung <frederick.che...@gmail.com> > > > > > > wrote: > > > > > > > > On 9 Sep 2008, at 02:42, David wrote: > > > > > > > > > Yea, I am trying to just use the link_to_remote helper now, but aside > > > > > > > > from converting the array and using JSON, I can''t even get the > > > > > > > > link_to_remote to route now. I am using: > > > > > > > > > <%= link_to_remote ''Click me'', :url => {:action => "update"}, :with > > > > > > > > => ''test'' %> > > > > > > > > > and the only action that works successfully is the new action, so > > > > > > > > > <%= link_to_remote ''Click me'', :url => {:action => "new"}, :with => > > > > > > > > ''test'' %> > > > > > > > > > routes successfully, but this is not what i want. I get this error in > > > > > > > > firebug: > > > > > > > > > POSThttp://localhost:3000/appointments/update500241ms. > > > > > > > > I assume that''s telling you that the server returned a 500 error, > > > > > > > which means check your logs. > > > > > > > > Fred > > > > > > > > > Do you have any idea why this is happening? > > > > > > > > > On Sep 8, 6:30 pm, Frederick Cheung <frederick.che...@gmail.com> > > > > > > > > wrote: > > > > > > > >> On 8 Sep 2008, at 22:54, David wrote: > > > > > > > > >>> Sorry, that ajax.request method should be a put, so: > > > > > > > > >>> new Ajax.Request(''/appointments/array/'', > > > > > > > >>> {method:''post'',postBody:"''data=''+myArray.toJSON"}); > > > > > > > > >> If you''re just posting json then you shouldn''t that data= (and you > > > > > > > >> look like you''re writing a link_to_remote :with option - right now > > > > > > > >> you''re posting the string "''data=''+myArray.toJSON") > > > > > > > > >> something like > > > > > > > > >> postBody: Object.toJSON(myArray) > > > > > > > > >> is more like it. You might also need to set the content-type header > > > > > > > >> appropriately. > > > > > > > > >> Fred > > > > > > > > >>> On Sep 8, 2:52 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > >>>> 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(Unprocessable Entity) > > > > > > > >>>> error. Im not sure what is wrong. > > > > > > > > >>>> function test() > > > > > > > >>>> { > > > > > > > >>>> for(i=1;i<22;i++){ > > > > > > > >>>> if (document.getElementById(i+''d'').className => > > > > > > >>>> "selected"){ > > > > > > > >>>> myArray.push(i); > > > > > > > >>>> } > > > > > > > >>>> } > > > > > > > > >>>> new Ajax.Request(''/appointments/array/'', > > > > > > > >>>> {method:''get'',postBody:"''data=''+myArray.toJSON"}); > > > > > > > > >>>> } > > > > > > > > >>>> Thanks for any input!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---