I'm sending my rails API requests from an Android app using Volley. This is the search method in question that takes a query string for params (and utf8).
def index
@items = Item.search(params)
end
My request url looks like this:
"https://www.myapp.com/api/items.json/?utf8=✓&query=" + query;
// query is a string from user input
I'd like to split query
into a query string, as currently query
is just a string.
I was hoping I could do something like:
def index
my_params = # turn query into query string, make new hash with results and utf8 param
@items = Item.search(my_params)
end
How do I accomplish that? Alternatively, is there a good way to split query
up before it's sent from the client side? In this case, query
could contain any number of words.
UPDATE
To be clear, I'm asking how to turn the existing param query
(which looks like: "large red balloons"
), into a proper query string that I can pass to my method.
What my method is expecting in the params would be like:
utf8=✓&query=large+red+balloons