Question

Need to be able to generate the following URL string

http://localhost:3000/admin/cities?q%5Bprovince_id_eq%5D=1&commit=Filter&order=city_name_asc

how does this link_to need to be setup?

link_to(p.cities.count, admin_cities_path)
Was it helpful?

Solution

You could just pass the query parameters as a hash to the URL helper, e.g. Running the following commands in my console, I get the following hash:

url = "http://localhost:3000/admin/cities?q%5Bprovince_id_eq%5D=1&commit=Filter&order=city_name_asc"    
query = URI.parse(url).query
hash = Rack::Utils.parse_nested_query(query)
#=> { "q" => { "province_id_eq" => "1" }, "commit" => "Filter", "order" => "city_name_asc" }

Then you'd just do

admin_cities_url(hash)

To get back to the original URL.

OTHER TIPS

Probably this will help you, take a look after the "link_to can also produce links with anchors or query strings"

link_to(p.cities.count, admin_cities_path(q: { province_id_eq: 1 }, order: "city_name_asc"))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top