SessionsHelper in railstutorial.org: Should helpers be general-purpose modules for code not needed in views?

前端 未结 4 1630
失恋的感觉
失恋的感觉 2020-12-14 19:13

railstutorial.org has a suggestion which strikes me as a little odd.

It suggests this code:

class ApplicationController < ActionController::Base         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 19:38

    They seem to be taking (sneaky) advantage of the fact that, in Rails, Helpers are just ruby Modules.

    Placing behavior that is shared across Controllers in a Module is, in my opinion, good practice. Putting it in a Helper, on the other hand, is potentially misleading and I would avoid it. Place it in a “standard” Module.

提交回复
热议问题