【发布时间】:2017-03-15 10:28:26
【问题描述】:
我需要按照Rails API ActionView::Helpers::TextHelper 的说明在rails 控制台中执行此操作 我已经在下面的Stackoverflow Discussion 找到了我的问题的解决方案,但我认为这个问题可能对发布很有用。 如果你想让我删除它,请告诉我。
-
我想在我的 rails 控制台中创建一个
ActionView::Helpers::TextHelpertexthelper = ActionView::Helpers::TextHelper => ActionView::Helpers::TextHelper -
我创建一个字符串
string = "I want to call the truncate method" => "I want to call the truncate method" -
我想在我的控制台上调用 truncate 方法,在这个字符串上。
truncate(string, length: 25, omission: '... (continued)') => "And they f... (continued)"
当我在控制台输入时:
truncate("Once upon a time in a world far far away", length: 17, separator: ' ')
我收到了
undefined method `truncate' for main:Object
整个想法来自这篇文章.. Undefined method `truncate' in model
【问题讨论】:
标签: ruby-on-rails ruby