ruby on rails - Append query string to url -
i have callback url string params[:callback]
, need append query string "&result=true"
, redirect user. better way found of doing using addressable
think code big task when talking ruby:
callback = addressable::uri.parse(params[:callback]) query = callback.query_values query[:result] = 'true' callback.query_values = query redirect_to callback.to_s
is there more elegant way of getting same result snippet?
- if don't need url validations can (looks little bit dirty):
url = params[:callback] redirect_to url + (url.include?('?') ? '&' : '?') + 'result=true'
- otherwise have use either external library (like addressable) or uri module standard library
Comments
Post a Comment