Append query string to url

后端 未结 6 1504
[愿得一人]
[愿得一人] 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:40

    years later, I find a better solution of this problem.

    Get the value from the super first, then do any tweaks we need using Addressable

    def url_for(options={})
        val = super
        if params[:locale].present?
            parsed = Addressable::URI.parse(val)
            query_array = parsed.query_values(Array) || []
            query_array << ['locale', params[:locale]]
            parsed.query_values = query_array
            val = parsed.to_s
        end
        val
    end
    

提交回复
热议问题