Rails:跨类的复选框列表

时间:2015-03-24 00:44:03

标签: ruby-on-rails ruby-on-rails-4

如果我在表单中加载资源如下:

def custom_articles
  @user.custom_articles + @user.edited_articles || []
end

它们会被输出到一个复选框列表中,如何区分EditedArticleCustomArticle是什么? custom_articles也被添加到Component的集合中。

1 个答案:

答案 0 :(得分:2)

如果您需要保留上下文,请保留上下文!为什么你不能传回一个不会踩到该类型的哈希值而不是传回一个数组呢?

def custom_articles
  {custom: @user.custom_articles, edited: @user.edited_articles}
end

编辑:

  custom_articles[:edited]

定制

  custom_articles[:custom]

所有文章:

  custom_articles.values.flatten