1
爲什麼下面的代碼爲我生成不同的輸出?爲什麼「<%= @ comments.each {| comment | comment.title}%>」不會產生評論標題,而會產生「comment.inspect」...?
<% @comments.each do |comment| %>
<%= comment.title %>
<% end %>
生產:
Title 1 title 2
但
<%= @comments.each { |comment| comment.title } %>
生產:
[#<Comment id: 1, commentable_id: 1, commentable_type: "Entry", title: "Title 1", body: "bla", subject: "", user_id: 1, parent_id: nil, lft: 1, rgt: 2, created_at: "2012-07-31 06:15:26", updated_at: "2012-07-31 06:15:26">, #<Comment id: 2, commentable_id: 1, commentable_type: "Entry", title: "tile 2", body: "one more comment", subject: "", user_id: 1, parent_id: nil, lft: 3, rgt: 4, created_at: "2012-08-01 06:58:57", updated_at: "2012-08-01 06:58:57">]
我在哪裏可以找到'&'在這方面的文件? – deefour 2012-08-06 14:48:26
http://ruby-doc.org/core-1.9.3/Symbol.html#method-i-to_proc – 2012-08-06 14:57:00
非常感謝! – deefour 2012-08-06 14:57:18