Rails-在此代码行中instance:topic是什么意思?

问题描述

| 它说:topic,那是做什么的?据我了解,如果是您的模型,:topic也可以是:posts。但是为什么要确切地指定呢?谢谢
 def favorable(opts={})

  # favorable_type
  type = opts[:type] ? opts[:type] : :topic  
  type = type.to_s.capitalize

解决方法

:topic
是一个符号,基本上是一个字符串。因此,如果
opts
哈希中没有
:type
键,则为
type = \"Topic\"
。 我想他们使用的是
:topic
而不是
\"Topic\"
,因为
opts[:type]
会返回符号,也许是
:whatever
,并且他们想将type设置为
\"Whatever\"