58

helper.method_name worked in some version of Rails... are there ways that work in both Rails 2.2.2, 2.3.5, and 3.0.1? (to use all view and helper methods)

nonopolarity
  • 146,324
  • 131
  • 460
  • 740

2 Answers2

95

You can also try :

YourController.helpers.my_helper

for example :

> ApplicationController.helpers.content_tag(:div, "test")
=> "<div>test</div>" 

This works with Rails 2, 3 and 4.1

Nishant Kumar
  • 363
  • 4
  • 20
Nicolas Blanco
  • 11,164
  • 7
  • 38
  • 49
59

please try to this

rails console
helper.any_method_of_helper(pass_argument)

example

helper.number_to_currency('123.45')
scarver2
  • 7,887
  • 2
  • 53
  • 61
  • 1
    This works. However there is an additional case wherein if you have defined your helper methods inside a file nested inside a module for e.g. `MyModule::ModuleSpecificViewHelper` (defined at `/app/helpers/my_module/module_specific_view_helper.rb`), then in rails console you should include that module first (if not already included) and then try `helper.your_method` and you should get it. – Jignesh Gohel Nov 22 '17 at 10:42
  • Work like a charm for Rails 4.2.11 – Slava Zharkov Mar 05 '19 at 13:53
  • And also like a charm in Rails 5.2! – Joshua Pinter Jan 29 '22 at 21:48