Question

Probably something wrong with my setup:

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

Looks like I cannot use any text helpers (both in irb and rails console).

What should I check?

Was it helpful?

Solution

The Rails Console exposes the helper methods through the helper variable. Therefore, please, use this instead:

helper.truncate("Once upon a time in a world far far away", :length => 17)

for more, please read this article on 37signals.com

OTHER TIPS

type following line into your rails console

include ActionView::Helpers

now your helpers are accessible during the entire rails console session and you can continue like…

truncate("Once upon a time in a world far far away", :length => 17)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top