2012-07-23 63 views
0

我在RJS下面的代碼:RJS - 紅寶石環路內page.alert

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內他們的名字?

感謝您的寶貴幫助

回答

3

使用Array.join

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

Ultimation的suggession:如果數組包含模型,而不是字符串,你需要將它們映射到標題:

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

或者如果他們是我會建議做的對象:@ books_by_author.collect {| x | x.title} .join(「\ n」) – Ultimation 2012-07-23 14:36:35

+0

非常感謝:) – Kim 2012-07-23 14:37:20