Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any example Rails apps where business logic is kept in separate classes than ActiveRecord?

There's been a recent surge in the Ruby community of blog posts, tweets, and comments on the benefits of using better OO design, and specifically separating business logic from persistence logic. Especially for larger apps, I see this as excellent advice.

  • http://solnic.eu/2011/08/01/making-activerecord-models-thin.html
  • http://blog.steveklabnik.com/2011/09/06/the-secret-to-rails-oo-design.html
  • http://avdi.org/devblog/2011/11/15/early-access-beta-of-objects-on-rails-now-available-2/

I'm interested to find a complete example Rails app where the business logic and been completely decoupled from the ORM (ActiveRecord or otherwise). Specifically, I'm interesting in seeing how one might handle DB constraints, business rule validation, parameter cleaning, service classes, etc.

Anyone know of an open-source app like this?

like image 462
Ben Crouse Avatar asked Nov 22 '11 18:11

Ben Crouse


2 Answers

The ones I am familiar with are from Jeff Casimir (@j3). Here is his presentation from Railsconf 2011. He also created a gem called draper that uses some of those ideas. Ryan Bates made a rails cast using it so hopefully that gives you some ideas.

like image 147
Vincent Agnello Avatar answered Nov 19 '22 13:11

Vincent Agnello


As far as I know - railists approach modeling business quite differently. They more or less consciously drive design in data-centric way. It might seem contradictory and bad if we cling to e.g. object orientation.

But, as christians say: "freedom comes from constraints".

If we are able to express our domain in CRUD like fashion, we greatly decrease technical complexity, get REST for free etc.

This blog post explains it better than I do (don't miss presentation by DHH)

And here's some insight from Scott Belware on this topic.


But if you insist and want to experiment a bit, you might want to try data-mapper.
Unfortunately, haven't tried that out yet, so - can't comment.

like image 44
Arnis Lapsa Avatar answered Nov 19 '22 13:11

Arnis Lapsa