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 开发者_StackOverflow中文版
type = type.to_s.capitalize
:topic
is a symbol, which is basically a string. So, if there's no :type
key in the opts
hash, type = "Topic"
.
I suppose they're using :topic
instead of "Topic"
because the opts[:type]
would return a symbol, maybe :whatever
and they want to set type to "Whatever"
.
精彩评论