我正在构建一个非常简单的Ruby on Rails博客应用程序,并在主页上显示最近的评论。我想限制从“评论”表中的“正文”列显示的字符数。我假设只需在“<%=h comment.body %>”代码末尾添加一些内容即可,但由于我对Ruby和Rails都很新,不知道该添加什么。
这是我在 /views/posts/index.html.erb 文件中的代码:
这是我在 /views/posts/index.html.erb 文件中的代码:
<% Comment.find(:all, :order => 'created_at DESC', :limit => 5).each do |comment| -%>
<p>
<%=h comment.name %> commented on
<%= link_to h(comment.post.title), comment.post %><br/>
<%=h comment.body %>
<i> <%= time_ago_in_words(comment.created_at) %> ago</i>
</p>
<% end -%>
j
是javascript
转义助手的简写一样)。 - Sampson Crowley