Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

“undefined method” when calling helper method in ApplicationHelper module from controller in Rails3 app

#5848

I define a method in ApplicationHelper module

module ApplicationHelper

def mymethod

end

end

class MyController < ApplicationController
def show

   mymethod

end end

When i call it from my controller, just get the "undefined method" message.

Reported by inetufo · October 20th, 2010 @ 03:07 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Luis Hurtado
    Luis Hurtado

    Are helper methods intended to be used in controllers?
    I think helper methods MUST to be used only in views.

    October 20th, 2010 @ 05:32 PM

  2. Aditya Sanghi
    Aditya Sanghi
    • State changed from new to invalid
    • Importance changed from to Low

    Yes, helpers are meant to be used in Views not Controllers. If you want to use them in Controllers you can try to access them as @template.mymethod but i'm not it's a documented public way of doing it. There maybe other workaround to access them in controllers, feel free to investigate.

    October 20th, 2010 @ 08:49 PM