Jeff Cohen
2006-Apr-19 18:32 UTC
[Rails] how to pass a hash as a parameter in link_to_remote
When using link_to_remote, I''d like to pass along some auxiliary data in the request. It''s a hash of dynamic data that can change with each request. But I get an error when rails trying to "stringify" the hash. For the regular link_to, it works because it turns the hash into a regular GET-like query string. I''m expecting to be able to get my hash as params[:myhash] # => my hash data inside my controller action, but this only works for link_to, not link_to_remote. My workaround was to write my own helper method to convert the hash into a querystring-looking string, and then to de-stringify inside the controller. But I feel like I must be reinventing the wheel. What''s the correct way to pass a hash to my controller in an ajax call? Thanks! Jeff -- Posted via http://www.ruby-forum.com/.
Rob Merrell
2006-Apr-19 23:12 UTC
[Rails] how to pass a hash as a parameter in link_to_remote
Jeff, I recently saw the same sort of discussion on the Utah Ruby User Group list. Here''s a link for the start of the tread. Just follow it through and hopefully you can find your answer. http://comox.textdrive.com/pipermail/talk/2006-April/000965.html Rob On 4/19/06, Jeff Cohen <cohen.jeff@gmail.com> wrote:> > When using link_to_remote, I''d like to pass along some auxiliary data in > the request. It''s a hash of dynamic data that can change with each > request. > > But I get an error when rails trying to "stringify" the hash. > > For the regular link_to, it works because it turns the hash into a > regular GET-like query string. > > I''m expecting to be able to get my hash as > > params[:myhash] # => my hash data > > inside my controller action, but this only works for link_to, not > link_to_remote. > > My workaround was to write my own helper method to convert the hash into > a querystring-looking string, and then to de-stringify inside the > controller. > > But I feel like I must be reinventing the wheel. What''s the correct way > to pass a hash to my controller in an ajax call? > > Thanks! > Jeff > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- c++: the power, elegance and simplicity of a hand grenade http://www.migrob.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060419/5dd4fe2f/attachment.html
Brian Eng
2006-Apr-20 15:49 UTC
[Rails] Re: how to pass a hash as a parameter in link_to_remote
Thanks for the link Rob. That''s exactly what I needed. For those interested, the best answer seems to be (from Jamis) to base64 your hash, and decode it later. string = Base64.encode64(Marshal.dump(hash)).strip hash = Marshal.load(Base64.decode64(string)) Brian softiesonrails.com -- Posted via http://www.ruby-forum.com/.