NoMethodError when trying to invoke helper method from Rails controller

前端 未结 14 1157
滥情空心
滥情空心 2020-11-30 20:05

I\'m getting a NoMethodError when trying to access a method defined in one of my helper modules from one of my controller classes. My Rails application uses the

14条回答
  •  北海茫月
    2020-11-30 20:57

    if you need to share a method between a controller and helper/view, you can just define via 'helper_method' in the top of the controller:

    class ApplicationController < ActionController::Base
      helper_method :my_shared_method
      ...
    
      def my_shared_method
        #do stuff
      end
    end
    

    hope that helps

提交回复
热议问题