Two-Dimensional Hashes through links?


#1

I’m really hitting a wall here. My program has a search engine, returns
a list of results. I am using a two-dimensional hash to pass the form
data back to my controller. (i.e. params[:job] => {:description =>
“xxx”, :location => “xxx”, company => “xxx”}) I use that Job object to
search my database, and then wait for user input.

Now when the search is returned if the user wants to sort the list I
need to pass that two-dimensional hash back into my controller along
with a sort criteria but I cannot seem to do this. I am using
link_to_remote and it just kills any hash that is not 1 dimensional. I
was told that GETs can only send 1 dimensional hashes so I set
link_to_remote to send a POST request:

link_to_remote(“mylink”, :url => {:job => params[:job], :sort =>
sort_choice}, :post => true}

According to WebBrick there is a POST request being sent, but my
two-dimensional hash is still be killed. (turned into 1 dimensional
string) Is there any way at all to send a two-dimensional hash through a
link? Or is this a fundamental limitation of HTTP?


#2

On 18-mei-2006, at 22:55, Brian C. wrote:

link_to_remote and it just kills any hash that is not 1 dimensional. I
link? Or is this a fundamental limitation of HTTP?
No, this is a little deficiency of ActionPack. If you care you can
bug the core about the patch that makes it possible.

http://dev.rubyonrails.org/ticket/4947


Julian ‘Julik’ Tarkhanov
please send all personal mail to
me at julik.nl


#3

Julian ‘Julik’ Tarkhanov wrote:

On 18-mei-2006, at 22:55, Brian C. wrote:

link_to_remote and it just kills any hash that is not 1 dimensional. I
link? Or is this a fundamental limitation of HTTP?
No, this is a little deficiency of ActionPack. If you care you can
bug the core about the patch that makes it possible.

http://dev.rubyonrails.org/ticket/4947


Julian ‘Julik’ Tarkhanov
please send all personal mail to
me at julik.nl

Oh wow, thank-you very much. I’ll send the dev-team a note asking for
the patch to be added to a future build.


#4

I’m finding that if I need to pass around a complex hash the best option
is to encode it like so:

@my_encoded_hash = Base64.encode64(Marshal.dump(my_complext_hash)).strip

this will give you your has encoded as a string value which you can pass
between your view and controller more easily.
To get back your original hash use something like:

@my_decoded_hash = Marshal.load(Base64.decode64(params[:conditions]))

Full credit for the above goes to Jamis B…

Cheers

Jonathan

http://www.agileevolved.com