Flatten a Hash into a String

Using join to create a key value string

Flatten a Hash into a String

Join is a powerful method that can be used in a variety of ways. It helps to ease the pain of working with various collections including hashes.

Here is a simple technique on how to join a hash into a url name value pair.

param_string = params.map{|k,v| "#{k}=#{v}"}.join('&')

Take a look at [Url Encoded String](/how-do-i/ruby/url-encoded-string/) article for how to encode the values.

For more details on the ways to do this check out the stack flow article Flattening hash into string in ruby.