page.alert中的ruby循环



我的rjs文件中有以下代码:

if @books_by_author.count != 0
page.alert("The following books reference the author you want to delete: n
     # here i want to list all the books referencing the author
");
end

如何循环浏览@books_by_author并在page.alert中显示它们的名称?

感谢您的宝贵帮助

使用Array.join:

page.alert("The following books reference the author you want to delete: n
            #{@books_by_author.join(', /n')} ");

Ultimation的建议:如果数组包含模型,而不是字符串,则需要将它们映射到标题:

page.alert("The following books reference the author you want to delete: n
            #{@books_by_author.map(&:title).join(', /n')} ");

相关内容

  • 没有找到相关文章

最新更新