TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Pub/Sub system events for post-action tasks in Rails

11 pointsby urbanautomatonover 12 years ago

2 comments

pselbertover 12 years ago
While I like the idea of cleaning up unrelated activities I don't think observers or subscribers are an ideal solution. In a system of non trivial size, or even a system where you haven't worked in a particular model for a while it can become difficult to track down what is acting and when.<p>When you need to bundle activity together a much better approach is to move it out of the controller and into a dedicated class. It isn't practical to test a controller in isolation, but quite simple to test a PORO.<p>When you extract the activities into a class you are forced to name the behavior outside the context of some controllers "create" action. Testing, readability, and complexity wins.
评论 #4632509 未加载
xentroniumover 12 years ago
Implementing such system is a very tough call, actually. As complexity of your application increases, you stop understanding what happens when. The arguments for and against pub/sub callbacks are basically the same as with rails Observers and Sweepers.<p>I personally felt that their original code was not that bad.
评论 #4631561 未加载