My url looks like this:
http://localhost:3000/ads?utf8=✓&q%5Bbrand_eq%5D=ALFA+ROMEO&q%5Bmodel_eq%5D=GTV+%26+Spider&commit=Search
(generated by Ransack gem)
I want to receive from it 'model_eq' value, which in this example should look like this:
GTV & Spider
Is there any painless method to do this from JavaScript (CoffeeScript) in Rails?
You can use regex to extract data from the URL.
var url = 'http://localhost:3000/ads?utf8=✓&q%5Bbrand_eq%5D=ALFA+ROMEO&q%5Bmodel_eq%5D=GTV+%26+Spider&commit=Search';
var model = (url.match(/model_eq.*?=(.+)&/) || [])[1];
alert(decodeURIComponent(model));
The regex will extract the text that is after model_eq=
.