I’m trying to manually create some params to pass to a Rails controller function, why are keys to the params hash listed with the colon, e.g. params[:key] and not params["key"]?
I’m trying to manually create some params to pass to a Rails controller function,
Share
Rails uses ActiveSupport’s
HashWithIndifferentAccessfor almost all hashes that come from within itself, such asparams. AHashWithIndifferentAccessbehaves the same as a regular hash except key access by symbol or string of the same “value” returns the same hash value. For example:vs. a normal hash:
This allows you to not have to worry (for better or worse) about whether a particular key was a Symbol or a String.