gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:25:26 26 4
gpt4 key购买 nike

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

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

那是我检查 truncate 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

最佳答案

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

应该是

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

关于ruby-on-rails - rails 截断错误数量的参数(3 为 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11929571/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com