I have a sortable list that I serialize and pass to ruby to parse the results and update my array of hashes. eg. $tasks = [ { :id => 1, :name => ''Do the dishes'', :position => 3 }, { :id => 2, :name => ''Take out the trash'', :position => 2 }, { :id => 3, :name => ''Shovel the driveway'', :position => 1 } ] My hurdles: (1) serializing and passing with Ajax var list = Sortable.options(''tasks'').element; new Ajax.Request(''/tasks'', { parameters: Sortable.serialize(list)}); I get this: tasks%5B%5D=2&tasks%5B%5D=1&tasks%5B%5D=3 would it be more useful if It was formating it as such? task{id}={position}& Where are the %5B%5D coming from? (2) parsing it in ruby I grab the request with web brick and I pass the query to params params = request.query How do I go about parsing it and updating my array of hashes? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Heres a pastie link if that helps: http://pastie.caboo.se/145437 On Jan 30, 11:40 am, OmenKing <omen.k...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a sortable list that I serialize and pass to ruby to parse the > results and update my array of hashes. > eg. > > $tasks = [ > { :id => 1, :name => ''Do the dishes'', :position => 3 }, > { :id => 2, :name => ''Take out the trash'', :position => 2 }, > { :id => 3, :name => ''Shovel the driveway'', :position => 1 } > ] > > My hurdles: > > (1) serializing and passing with Ajax > > var list = Sortable.options(''tasks'').element; > new Ajax.Request(''/tasks'', { parameters: Sortable.serialize(list)}); > > I get this: > > tasks%5B%5D=2&tasks%5B%5D=1&tasks%5B%5D=3 > > would it be more useful if It was formating it as such? > task{id}={position}& > > Where are the %5B%5D coming from? > > (2) parsing it in ruby > > I grab the request with web brick and I pass the query to params > > params = request.query > > How do I go about parsing it and updating my array of hashes?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 30, 2008 10:40 AM, OmenKing <omen.king-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> (1) serializing and passing with AjaxTry using toJSON() on the collection, like: tasks = $A([ { :id => 1, :name => ''Foo'' }, { :id => 2, :name => ''Bar'' }, ]); tasks.toJSON()> Where are the %5B%5D coming from?Those are escaped characters. They need to be unescaped on the server.> (2) parsing it in rubySince you''re not using Rails, which has handy helpers for dealing with JSON, you need to include your own implementation to parse JSON or write your own. -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Even though JSON is really cool I''m not sure if thats what I need. I have the Pragmatic Prototype and Scriptaculous book and in there AJAX samples they didn''t need toJSON. check out my pastie. I just not sure how to work with serialized info once its passed to webrick. On Jan 30, 1:48 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 30, 2008 10:40 AM, OmenKing <omen.k...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > (1) serializing and passing with Ajax > > Try using toJSON() on the collection, like: > > tasks = $A([ > { :id => 1, :name => ''Foo'' }, > { :id => 2, :name => ''Bar'' }, > ]); > > tasks.toJSON() > > > Where are the %5B%5D coming from? > > Those are escaped characters. They need to be unescaped on the server. > > > (2) parsing it in ruby > > Since you''re not using Rails, which has handy helpers for dealing with > JSON, you need to include your own implementation to parse JSON or > write your own. > > -justin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 30, 2008 1:01 PM, OmenKing <omen.king-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Even though JSON is really cool I''m not sure if thats what I need.It may not be, but I think it''s the easiest method of passing arbitrary data objects back and forth. Prototype is certainly well equipped for it. To deal with serialized info you need to use a CGI library to pull out the parameters, which should handle the unescaping for you. -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
That would be the simpler solution but it may not be practical for my me. I''ll moving this code over to an asp classic system. I was just using it in ruby for simple testing and showing purposes. When should I use JSON over send requests with Ajax? On Jan 30, 2:18 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 30, 2008 1:01 PM, OmenKing <omen.k...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Even though JSON is really cool I''m not sure if thats what I need. > > It may not be, but I think it''s the easiest method of passing > arbitrary data objects back and forth. Prototype is certainly well > equipped for it. > > To deal with serialized info you need to use a CGI library to pull out > the parameters, which should handle the unescaping for you. > > -justin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 30, 2008 1:38 PM, OmenKing <omen.king-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > That would be the simpler solution but it may not be practical for my > me. > I''ll moving this code over to an asp classic system. > I was just using it in ruby for simple testing and showing purposes.Since this list is to discuss the Rails-spinoffs, mainly prototype and scriptaculous, whatever you do on the backend is something to discuss somewhere else. I try to help people if they''re using the built-in Rails helpers to generate their JavaScript for them, but generally server-side talk is best taken to other lists that specialize in the technology you are using. Especially if we''re talking about old school ASP ;)> When should I use JSON over send requests with Ajax?I''m not sure I understand your question. Are you asking when is it appropriate to use JSON to send data over Ajax? If so, the answer is really up to you. Some people use JSON exclusively for Ajax communication, and other people may use it rarely, if ever. It''s up to what works best for your environment/style. Since you mentioned switching to ASP, then maybe most of the questions you have in this thread are irrelevant since ASP will unescape parameters for you *and* have the methods in place to extract the values you are looking for in the Request object, like: Request("tasks[0]"). -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Im not the one implementing it in asp, or yet that I know of. I''d be railing if it were up to me. But for my testing purposes I''d like to know how its possible just passing a request similar to what Pragmatic did in there book. On Jan 30, 2:45 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 30, 2008 1:38 PM, OmenKing <omen.k...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > That would be the simpler solution but it may not be practical for my > > me. > > I''ll moving this code over to an asp classic system. > > I was just using it in ruby for simple testing and showing purposes. > > Since this list is to discuss the Rails-spinoffs, mainly prototype and > scriptaculous, whatever you do on the backend is something to discuss > somewhere else. I try to help people if they''re using the built-in > Rails helpers to generate their JavaScript for them, but generally > server-side talk is best taken to other lists that specialize in the > technology you are using. Especially if we''re talking about old school > ASP ;) > > > When should I use JSON over send requests with Ajax? > > I''m not sure I understand your question. Are you asking when is it > appropriate to use JSON to send data over Ajax? If so, the answer is > really up to you. Some people use JSON exclusively for Ajax > communication, and other people may use it rarely, if ever. It''s up to > what works best for your environment/style. > > Since you mentioned switching to ASP, then maybe most of the questions > you have in this thread are irrelevant since ASP will unescape > parameters for you *and* have the methods in place to extract the > values you are looking for in the Request object, like: > Request("tasks[0]"). > > -justin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---