MΓ³dulo 08 Β· REST & JSON Controllers β LecciΓ³n 2 de 5 Β· ~11 min
Params & Strong Params
One hash, three sources
Every controller action has access to a params hash, and it doesn't care WHERE a value came from β Rails merges three different sources into that one hash before your action ever runs:
- Path params β captured from the URL itself by the route:
/api/walkers/:idmeansparams[:id]is whatever segment sat where:idwas. - Query params β the
?key=valuepart of the URL:/api/walkers?city=Austinmeansparams[:city]is"Austin". - Body params β a JSON object sent in a POST/PATCH request body, parsed automatically into the same hash.
You've already used the first two without naming them: Walker.find(params[:id]) reads a path param, and walkers.in_city(params[:city]) if params[:city].present? (a real line from apps/pawwalk-api) reads a query param straight into the scope you built in module 07.