这是一个学校课程评分系统的评论页面,我想要做到:
1.统计每条一评论的字数
2.当整个loop结束以后统计出所有评论的字数总计
<div id="header">
<h1>Course Rating Information </h1>
<p>
Number:
<%= @course.number %>
</p>
<p>
Year:
<%= @course.year %>
</p>
<p>
Name:
<%= @course.name %>
</p>
</div>
<div id="pagebody">
<% if @course.comments.exists? %>
<h2>Ratings</h2>
<% @course.comments.each do |comment| %>
<p>
<strong>Commenter:</strong>
<%= comment.commenter %>
</p>
<p>
<strong>Comment:</strong>
<%= comment.comment %>
</p>
<% end %>
<% else %>
<h2>No ratings available</h2>
<% end %>
</div>
<div id="footer">
<%= link_to 'New Comment', new_course_comment_path(@course) %>
<%= link_to 'Back to course listing', courses_path %>
</div>
@course.comments.sum{ |cc| cc.comment.length }