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

后端 未结 4 1872
太阳男子
太阳男子 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:22

    Receive them as a param. Otherwise, as the app grows, it gets very difficult to trace where the instance vars are being set when refactoring, troubleshooting, etc.

    Also, I believe there's a general best practice to only use instance vars in views within the initial template...and from there you should pass the var into helpers and other partials.

提交回复
热议问题