Append query string to url

后端 未结 6 1546
[愿得一人]
[愿得一人] 2021-02-05 08:15

I have a callback url string params[:callback] and I need to append a query string \"&result=true\" and redirect the user. The better way I found o

6条回答
  •  执念已碎
    2021-02-05 08:45

    I think you're pretty close to optimal. you could crush out a line or two, but it doesn't really gain you anything.

    callback = Addressable::URI.parse(params[:callback])
    callback.query_values = callback.query_values.merge {:results => 'true' }
    redirect_to callback.to_s
    

    If the callback is always inside your application, you might have some other options with varying degrees of coolness, but you didn't specify if that was the case or not.

提交回复
热议问题