Does anyone know why I get
undefined method `my_method\' for #
when I call my_method(\"string\") from withi
view_context is your friend, http://apidock.com/rails/AbstractController/Rendering/view_context
if you wanna share methods between controller and view you have further options:
Maybe I'm wrong, but aren't the helpers just for views? Usually if you need a function in a controller, you put it into ApplicationController as every function there is available in its childclasses.
As far as i know, helper :all
makes the helpers available in the views...
Try appending module_function(*instance_methods)
in your helper modules, after which you could directly call those methods on the module itself.
You cannot call helpers from controllers. Your best bet is to create the method in ApplicationController
if it needs to be used in multiple controllers.
EDIT: to be clear, I think a lot of the confusion (correct me if I'm wrong) stems from the helper :all
call. helper :all
really just includes all of your helpers for use under any controller on the view side. In much earlier versions of Rails, the namespacing of the helpers determined which controllers' views could use the helpers.
I hope this helps.
helpers are for views, but adding a line of code to include that helper file in ApplicationController.rb can take care of your problem. in your case, insert the following line in ApplicationController.rb:
include ApplicationHelper