Params hash keys as symbols vs strings
<%= params[:action] %>
and
<开发者_运维问答;%= params['action'] %>
display
index
but what is the difference between this syntax?
In Rails, the params
hash is actually a HashWithIndifferentAccess
rather than a standard ruby Hash
object. This allows you to use either strings like 'action'
or symbols like :action
to access the contents.
You will get the same results regardless of what you use, but keep in mind this only works on HashWithIndifferentAccess
objects.
精彩评论