Rails - How to use a Helper Inside a Controller

前端 未结 8 1228
生来不讨喜
生来不讨喜 2020-11-29 15:01

While I realize you are supposed to use a helper inside a view, I need a helper in my controller as I\'m building a JSON object to return.

It goes a little like this:

8条回答
  •  一整个雨季
    2020-11-29 16:01

    In general, if the helper is to be used in (just) controllers, I prefer to declare it as an instance method of class ApplicationController.

提交回复
热议问题