NoMethodError when trying to invoke helper method from Rails controller

前端 未结 14 1192
滥情空心
滥情空心 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:38

    Helpers are to be used with templates, ie. views, not in controllers. That's why you can't access the method. If you'd like to share a method between two controllers, you'd have to define it in ApplicationController, for instance. helper :all says that any method you define in any helper file in app/helpers directory will be available to any template.

提交回复
热议问题