Rails: Model instance method or helper method?

前端 未结 2 797
别那么骄傲
别那么骄傲 2021-01-04 09:40

By convention, should the following be defined as an instance method of my model or a helper method?

# app/models/user.rb
class User < ActiveRecord::Base
         


        
相关标签:
2条回答
  • 2021-01-04 10:18

    Go with the first (keep in model), also because you might want to do other stuff, like combined indexes :)

    0 讨论(0)
  • 2021-01-04 10:29

    Everything directly related to your model should stay in your model.

    This way, you keep coherent logic and tests.

    0 讨论(0)
提交回复
热议问题