如果我在表单中加载资源如下:
def custom_articles
@user.custom_articles + @user.edited_articles || []
end
它们会被输出到一个复选框列表中,如何区分EditedArticle
和CustomArticle
是什么? custom_articles
也被添加到Component
的集合中。
答案 0 :(得分:2)
如果您需要保留上下文,请保留上下文!为什么你不能传回一个不会踩到该类型的哈希值而不是传回一个数组呢?
def custom_articles
{custom: @user.custom_articles, edited: @user.edited_articles}
end
编辑:
custom_articles[:edited]
定制
custom_articles[:custom]
所有文章:
custom_articles.values.flatten