可能是我的设置有问题:
irb(main):001:0> truncate("Once upon a time in a world far far away", :length => 17)
NoMethodError: undefined method `truncate' for main:Object
from (irb):1
from /usr/lib64/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /usr/lib64/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /usr/lib64/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
看起来我不能使用任何文本助手(在 irb 和 rails 控制台中)。
我应该检查什么?
最佳答案
Rails 控制台通过 helper
变量公开辅助方法。因此,请改用它:
helper.truncate("Once upon a time in a world far far away", :length => 17)
更多请看这篇article on 37signals.com
关于ruby-on-rails - RubyOnRails : How do I use helper methods in Rails Console?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12942836/