"v1#index" My intention here is to grab the api method n...">

How to get only query string in Rails route?

I use this route

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

My intention here is to grab the api method name and then send a request to this method inside the controller.

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

I figured this would lead to sending other parameters as an argument to the method, but that didn't work. So my question is how to pass non-method parameters to the query string?

+7
ruby-on-rails-3 routing
source share
3 answers

#query_parameters does exactly what you want:

 request.query_parameters 

It is also the most efficient solution, because it does not create a new hash, as others do.

+7
source share

Stolen from work colleagues. I find this a bit more reliable solution, as it will work even if there are changes in the path parameters:

 params.except(*request.path_parameters.keys) 
+14
source share

I solved this problem by following these steps:

 params.except("method","action","controller") 
+6
source share

All Articles