RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Building a HTML url with parameters from a hash, DRY

Been breaking my nose on this for a good hour. Getting a splat hash argument into a html url to dry things up.

Comments

Hi Timon,

Great stuff, just taught me another use for splat!

What do you think of this: def build_url method, args params = args.map {|k,v| "#{k}=#{v}"}.join('&') url = 'http://your-url.com/'

url + method + params end </code>

Sorry, missed the ‘?’ – how’s this: def build_url method, args params = args.map{|k,v| "#{k}=#{v}"}.join('&')

“http://your-url.com/#{method}?#{params}” end </code>

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in