开发者

Params hash keys as symbols vs strings

开发者 https://www.devze.com 2023-03-14 06:05 出处:网络
<%= params[:action] %> and <开发者_运维问答;%= params[\'action\'] %> display index but what is the difference between this syntax?In Rails, the params hash is actually a HashWithIn
<%= 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消