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

后端 未结 3 1674
臣服心动
臣服心动 2021-02-20 14:22

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

相关标签:
3条回答
  • 2021-02-20 14:46

    Stolen from the work of a colleague. I find this a slightly more robust solution, since it will work even if there are changes to the path parameters:

    params.except(*request.path_parameters.keys)
    
    0 讨论(0)
  • 2021-02-20 15:01

    #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.

    0 讨论(0)
  • 2021-02-20 15:08

    I sort of solved this problem by doing this:

    params.except("method","action","controller")
    
    0 讨论(0)
提交回复
热议问题