Search code examples
ruby-on-railsrubyruby-on-rails-3irbactionviewhelper

RubyOnRails: How do I use helper methods in Rails Console?


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?


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