How can I get posted params in correct order?


#1

I’d like to have posted form field data in the same order they were in
the form.
Raw_post shows the data in correct order but params hash doesn’t. This
happens every time (tried it with webrick).

Any ideas how to get an array of objects in the correct order?


#2

… just realized that nested objects make correct ordering difficult.


#3

Heikki Ylönen wrote:

I’d like to have posted form field data in the same order they were in
the form.
Raw_post shows the data in correct order but params hash doesn’t. This
happens every time (tried it with webrick).

Any ideas how to get an array of objects in the correct order?
Unfortunately, that’s just a side-effect of the fact that hashes in Ruby
don’t preserve order. As far as I know, your options are to name your
fields in alphanumerical order so that you can do a
params.keys.sort.each {}, to keep an array with the keys in the right
order in the controller, or to manually parse them out of the raw_post.
None of these is particularly fantastic…