Rails Observer Alternatives for 4.0

前端 未结 12 789
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 05:29

With Observers officially removed from Rails 4.0, I\'m curious what other developers are using in their place. (Other than using the extracted gem.) While Observers were cer

12条回答
  •  伪装坚强ぢ
    2020-12-04 05:50

    I think the the issue with Observers being deprecated is not that observers were bad in and of themselves but that they were being abused.

    I would caution against adding too much logic in your callbacks or simply moving code around to simulate the behavior of an observer when there is already a sound solution to this problem the Observer pattern.

    If it makes sense to use observers then by all means use observers. Just understand that you will need to make sure that your observer logic follows sound coding practices for example SOLID.

    The observer gem is available on rubygems if you want to add it back to your project https://github.com/rails/rails-observers

    see this brief thread, while not full comprehensive discussion I think the basic argument is valid. https://github.com/rails/rails-observers/issues/2

提交回复
热议问题