Should Rails helpers assume an instance variable exists or should they receive them as parameters?

后端 未结 4 1874
太阳男子
太阳男子 2020-12-13 17:59

I\'m wondering if there\'s a specific programming principle (Demeter?) that supports the idea that Rails helpers should never use controller instance variables, rather, they

4条回答
  •  天命终不由人
    2020-12-13 18:23

    Since helper messages are mixed in to all controllers, hence available to all views (including partials and layouts), it's always wise to establish a clear contract - the parameters.

    The only exception I could think of is when a instance variable is also available to all views and controllers, like a menu or something similar.

提交回复
热议问题