开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜