0

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 内に表示するにはどうすればよいですか?

貴重なご協力ありがとうございます

4

1 に答える 1

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')} ");
于 2012-07-23T14:33:47.017 に答える