Rails - 实例:主题在这行代码中意味着什么?
哪里写着:主题,那是做什么的?据我所知 :topic 也可以是 :posts 如果这是你的模型。但为什么具体指定在那里呢?谢谢
def favorable(opts={})
# favorable_type
type = opts[:type] ? opts[:type] : :topic
type = type.to_s.capitalize
Where it says :topic, what is that doing? From what I can understand :topic could also be :posts if that is your model. But why is it specified there exactly? Thanks
def favorable(opts={})
# favorable_type
type = opts[:type] ? opts[:type] : :topic
type = type.to_s.capitalize
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
:topic
是一个符号,基本上是一个字符串。因此,如果opts
哈希中没有:type
键,则type = "Topic"
。我想他们使用
:topic
而不是"Topic"
因为opts[:type]
会返回一个符号,也许:whatever
并且他们希望将 type 设置为“Whatever”
。:topic
is a symbol, which is basically a string. So, if there's no:type
key in theopts
hash,type = "Topic"
.I suppose they're using
:topic
instead of"Topic"
because theopts[:type]
would return a symbol, maybe:whatever
and they want to set type to"Whatever"
.