Skip to content

Instantly share code, notes, and snippets.

@ryanbriones
Created February 6, 2014 14:44
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 ryanbriones/8845507 to your computer and use it in GitHub Desktop.
Save ryanbriones/8845507 to your computer and use it in GitHub Desktop.
Is there something in Ruby (in an existing gem?) that will take an HTML String, parse out a form, and return URI-encoded query string of the fields/values a la jQuery's form.serialize?
<form>
<input type="text" name="post[title]" value="Some Title" />
<textarea name="post[body]">This is my post body</textarea>
</form>
post[title]=Some%20Title&post[body]=This%20is%20my%20post%20body
@jnicklas
Copy link

jnicklas commented Feb 6, 2014

html = Nokogiri::HTML("...")
params = Capybara::RackTest::Form.new(nil, html).params({})
Rack::Utils.build_nested_query(params) #=> yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment