rails截断错误的参数数量(3为2)

时间:2021-07-13 00:06:10

Good day, I've this code in view, it generates

美好的一天,我看到了这个代码,它产生了

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">

That's where i check truncate http://paulsturgess.co.uk/articles/37-how-to-truncate-text-in-ruby-on-rails

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

And if i write

如果我写

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

I get

undefined method `reverse_merge!' for 40:Fixnum

1 个解决方案

#1


3  

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

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

should be

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

#1


3  

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

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

should be

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