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)
Asked
Active
Viewed 4.5k times
58

nonopolarity
- 146,324
- 131
- 460
- 740
2 Answers
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
-
How do I render a partial with this? Rails 4. `ApplicationController.helpers.render Post.last NoMethodError: undefined method 'include?' for nil:NilClass` – Chloe Feb 28 '14 at 02:53
-
>MyController.helpers.my_method(arg1, arg2); This is what I am looking for. – etlds May 28 '14 at 15:19
-
1In Rails 5+ I use only: helper.method_name(parameters) – Leandro Castro Nov 19 '20 at 14:04
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
-
1This 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
-
-