DRY Controllers in Rails 3.2

前端 未结 3 2350
有刺的猬
有刺的猬 2021-02-15 15:00

Following code climate analysis, I found that my controllers are not DRY as it could be. The methods like:

   def index
    @animals = current_user.animals.valid         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-15 15:21

    There is no need to make the code DRY in the way you stated. Think about it, one of the primary purpose of making your code DRY is that if you update the code in one place, you won't have to update the code in another place. However, in your case, if you update your code in Controller X, what are the chances you are going to make the same change in Controller Y? If no, then it's not a good candidate for abstraction. (In fact if you are even going to remotely change something in X which will not affect Y, then it's a bad candidate for DRY-ness)

    Generally, abstraction is good. However, over-abstraction is not a good thing, and it should be avoided.

提交回复
热议问题