Reputation: 2781
I made GET request with the following url in postman
localhost:8091/trade/search?side=SELL
Rails should have triggered searchTrade action
get '/trade/search/:commodity/:side/:counterparty/:location' => 'tradeservice#searchTrade'
Rails misinterpreted the route as:
match '/trade/:id', to: 'tradeservice#getTradeById', via: :get
Rails version: 5.1.7 Ruby version: 2.3.3.p222
This is definitely a bug, how do i fix this ??
Upvotes: 0
Views: 186
Reputation: 893
Rails routes are matched in the order they are specified (source).
/trade/search
matches both /trade/search
and /trade/:id
since :id
is a param.
The fix would be to place
get '/trade/search/:commodity/:side/:counterparty/:location' => 'tradeservice#searchTrade'
above
match '/trade/:id', to: 'tradeservice#getTradeById', via: :get
You might also want to make your endpoint look like this:
get '/trade/search' => 'tradeservice#searchTrade'
since you pass the params in the query string (?side=SELL
) rather than in the path.
Upvotes: 3