The value '/patients/:id'
is a normal Ruby string, and although the :id
part looks like a symbol, it is not.
When Rails parses the string, it uses the colon to identify a parameter name in the path. When it sets the parameter from receiveing a request like GET /patients/1
, it does not attempt to alter the symbol value, but does something like the following
params[:id] = '1'
Note I'm not 100% certain that is doesn't just use the string "id"
as the key here. But either way you can see it does not alter any symbol value, but just uses the name of the symbol so you know which key it will be stored under in the params Hash
The similarity between ':id'
as part of the URL parameter definition and for when you use the Symbol
literal :id
might be confusing, but is a design choice shared used in Rack path handling engine so most Ruby web frameworks use the same style.