Search code examples
ruby-on-railshashget

Rails how to put hash as parameter into url?


Since I have one hash object which needs to be passed into GET request. The hash should look like this

@filter = {
  "type" => "credit",
  "status" => "1",
  "invoice_type" => "1"
}

I make the request URL in this way

@report_url = "#{url}?filter=#{@filter}"

However, in this case, when I access params[:filter] in that GET controller, it will be "{".

How do I make it become

{
  "type" => "credit",
  "status" => "1",
  "invoice_type" => "1"
}

Solution

  • Try the following:

    @report_url = url + "?" + { filter: @filter }.to_query