Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get only the query string in a Rails route?

I am using a route like this

match "/v1/:method" => "v1#index"

My intention here is capture the name of the api method and then send the request to that method inside the controller.

def index
    self.send params[:method], params
end

I figured this would send the other parameters as an argument to the method, but it didn't work. So my question is how can I pass the non-method parameters in a query string?

like image 746
picardo Avatar asked Nov 07 '10 04:11

picardo


1 Answers

#query_parameters does exactly what you want:

request.query_parameters

It's also the most efficient solution since it doesn't construct a new hash, like the other ones do.

like image 186
Agis Avatar answered Sep 20 '22 23:09

Agis