我的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中显示其名称?
感谢您的宝贵帮助
答案 0 :(得分:3)
使用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')} ");