Skip to content

Instantly share code, notes, and snippets.

@jdelStrother
Created January 16, 2018 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdelStrother/7d673acbd52e12fb434433e9f2306bd1 to your computer and use it in GitHub Desktop.
Save jdelStrother/7d673acbd52e12fb434433e9f2306bd1 to your computer and use it in GitHub Desktop.
def flatten_to_form_value_pairs(params)
params.to_query.split("&").map { |component| component.split("=").map { |s| Rack::Utils.unescape(s) } }
end
params = {post: {title: "foo", category_ids: [1,2,3]}}
flatten_to_form_value_pairs(params)
[
["post[category_ids][]", "1"],
["post[category_ids][]", "2"],
["post[category_ids][]", "3"],
["post[title]", "foo"]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment