4 ms·
Something feels wrong to use Current.account in models.
by hartator 3y ago
Something feels wrong to use Current.account in models.
- lobstrosity420 3y agoIt is in fact how it was designed to be used, you can read the reasoning here: https://dev.37signals.com/globals-callbacks-and-other-sacrileges/ https://dev.37signals.com/globals-callbacks-and-other-sacril...
- Toutouxc 3y agoThe reasoning being basically "fuck Ruby and consistent OOP practices, this is how we roll". I used to be fine with this, but the more I work with Rails, the more I feel like it's trying to make me a worse programmer. Business logic in controllers, service "objects" (not actually objects at all), the OOP abomination that are models with dozens of different behaviors and agendas inherited via concerns. In Rails you can always pick your poison, but you don't seem to be allowed not to be poisoned.
- lobstrosity420 3y ago> Maximalist positions are a thing in our industry. Take a technique, outline its drawbacks, extrapolate you can’t use it under any circumstance, and ban it forever. We are lucky that Rails embraces exactly the opposite mindset as one of its pillars.
- revscat 3y agoYou may want look into dry-transaction and railway oriented programming.
- arrowsmith 3y agoOr you could give it up and move to Phoenix; I've never looked back.
- revscat 3y agoLink?
- arrowsmith 3y agohttps://phoenixonrails.com https://phoenixonrails.com
- ljm 3y agoI see conventions like that as an acknowledgement that Rails often gives up purity in favour of simplicity. It makes this decision quite often, primarily because it works for Basecamp, but also it keeps the mental model simple, especially for juniors learning the ropes. I've not seen many places that actually use it. Instead there are several other layers of patterns that try to keep things decoupled but introduce a different kind of complexity. And the implementation is different every time (Ruby devs love their custom service/command DSLs).
- huntedsnark 3y agoYeah I think it's one of those features that people generally steer away from. Ironically, if you stick to the "Rails way" of doing things I don't think you would ever encounter it.
- pavelevst 3y agoAgree, models just data layer, not a place for business logic IMO