Passing a list of same parameters with a different value

51 views Asked by At

So basically I was creating some client methods that would create a path to hit an external service. Also, I am using addressable gem.

Here is an example:

def get_member(ord_id, member_id)
  path = '/organizations/{ord_id}/people/{member_id}'
  hash = get(path, member_id: member_id, org_id: ord_id)

  { Member.custom_deserialize_method(hash) }
end

This works if the path is simple as above.

Now I want to write a method for a different path which does a bulk look up like this:

organizations/ab9176be/members/bulk?memberId=8e936891&memberId=b71c4f1e  (This is not a web url. Its a service end point)

The above method can have multiple memberId params. I know addressable has an expand method and ruby has a to_param method.

But I do not not know if that would help in my situation. I would appreciate some help here.

1

There are 1 answers

1
Richard Peck On

Route Globbing

I'm sure if this will help, but considering you've had no responses, I felt I'd be best posting

I learnt about route globbing a few weeks back. Bascially this allows you to define routes like this:

get 'books/*section/:title', to: 'books#show'

Would match books/some/section/last-words-a-memoir with params[:section] equals 'some/section', and params[:title] equals 'last-words-a-memoir'.


Although not directly related to the solution for your question, it may help you appreciate how Rails processes some of the routes in the app. Essentially, it means you can add as many "wildcard" routes as you need, with the various elements of the route being compiled in the params hash