2012-08-13 53 views
1

美好的一天,我在查看這個代碼,它會產生軌道截斷錯誤的參數數目(3 2)

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 
+1

對於這類事情,你可能想看看[API](http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html #method-i-truncate)而不是在將來的博客文章中:-) – Mischa 2012-08-13 07:10:05

回答

3

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

應該

<% output_text = truncate(article.text, :length => 40, :omission => '...') %> 
相關問題