1

美好的一天,我看到了这段代码,它会生成

wrong number of arguments (3 for 2)
Extracted source (around line #7):

4:     <h3 class="<%= cycle('color_1', 'color_2')  %> ">
5:       <%= link_to sanitize(article.title),article %>
6:     </h3>
7:     <% output_text = truncate(article.text, 40, "...") %>
8:     <span><%= sanitize(output_text) %>
9:       <%= link_to ' ... full ->',  article %></span>
10:     <span style="display: none">

那就是我检查截断的地方http://paulsturgess.co.uk/articles/37-how-to-truncate-text-in-ruby-on-rails

如果我写

<% output_text = truncate(article.text, 40) %>

我明白了

undefined method `reverse_merge!' for 40:Fixnum
4

1 回答 1

3

<% output_text = truncate(article.text, 40, "...") %>

应该

<% output_text = truncate(article.text, :length => 40, :omission => '...' ) %>
于 2012-08-13T07:08:42.827 回答