ActiveRecord Query返回ID数组,但我想要链接

时间:2015-04-09 00:10:22

标签: ruby-on-rails activerecord

我有一个查询

pack.pages.where("thumbnail is null or printable_page is null or preview is null or vuforia_archive is null or unity_bundle is null")

作为示例返回页面IDS列表[34,54,15]

但我想要的是指向每个编辑页面的链接(此代码对于一个页面为edit_admin_page_path(page)

[345415]

1 个答案:

答案 0 :(得分:1)

你可以获得这样的逗号分隔页面链接列表,如果这是你想要的:

pack.pages.where("thumbnail is null or printable_page is null or preview is null or vuforia_archive is null or unity_bundle is null").map{|page| edit_admin_page_path(page)}.join(',')

或者如果你想要HTML:

pack.pages.where("thumbnail is null or printable_page is null or preview is null or vuforia_archive is null or unity_bundle is null").map{|page| "<a href='#{edit_admin_page_path(page)}'}>#{page.id}</a>"}.join()