We have been moving the complex logic out of the models into libraries. But we are not happy with this approach. We also find it difficult to cleanly develop views where data is needed from several different models. The whole Rails REST and MVC model gets in the way. Would love to hear about how other wiser people have deal with these situations.
Where the logic hides in rails apps
21–30 of 56 posts
Re: Where the logic hides in rails apps
#22This is the sanest Rails design-advice that I've read in a long time. It counters the misguided "implicit over explicit"-mantra that is both very prevalent in the rails-community and also the source of most problems. I.e. when you watch any random RailsCast it is usually filled to the rim with obscure incantations and "look how we need only one LoC to perform $excessive_magic"! The end-result are those deeply entangl…
I agree with your sentiment in general, but what do you suggest to use in place of devise? Surely you're not suggesting to write all the code for handling mail confirmation, password changes etc. yourself?
Re: Where the logic hides in rails apps
#23This is the sanest Rails design-advice that I've read in a long time. It counters the misguided "implicit over explicit"-mantra that is both very prevalent in the rails-community and also the source of most problems. I.e. when you watch any random RailsCast it is usually filled to the rim with obscure incantations and "look how we need only one LoC to perform $excessive_magic"! The end-result are those deeply entangl…
Thereby, they seek to write as few lines of code as possible, at the expense of the sanity of everyone else.
Furthering the goals of the dark one all along...
Re: Where the logic hides in rails apps
#24This is the sanest Rails design-advice that I've read in a long time. It counters the misguided "implicit over explicit"-mantra that is both very prevalent in the rails-community and also the source of most problems. I.e. when you watch any random RailsCast it is usually filled to the rim with obscure incantations and "look how we need only one LoC to perform $excessive_magic"! The end-result are those deeply entangl…
steer clear from most of the entrenched practices and packages (e.g. devise and related trainwrecks) I agree with your sentiment in general, but what do you suggest to use in place of devise? Surely you're not suggesting to write all the code for handling mail confirmation, password changes etc. yourself?
https://github.com/binarylogic/authlogicRe: Where the logic hides in rails apps
#25I'll give a proposal now: every chair of every developer shall from now on give them electric shock whenever they use the term "business logic". Ouch. Seriously, "CreatesContact" is not really a class. It's a procedure, function with side effects, whatever you call it. Just with a class wrapper that boosts the developer ego almost as much as an AbstractFactoryManagerFactory. No, modules are actually great. If you hav…
even better, force them to use COmmon Business Oriented Language
Re: Where the logic hides in rails apps
#26We have been moving the complex logic out of the models into libraries. But we are not happy with this approach. We also find it difficult to cleanly develop views where data is needed from several different models. The whole Rails REST and MVC model gets in the way. Would love to hear about how other wiser people have deal with these situations.
I think what you are in need is nothing to do with model separation. But, you need to be careful about which code belongs to your business logic. For the views you mentioned, I don't know your code but I think you may use something interim, like a presenter code which takes data from the models and helps views to show it.
..something like a "controller"? :P
Re: Where the logic hides in rails apps
#27This is the sanest Rails design-advice that I've read in a long time. It counters the misguided "implicit over explicit"-mantra that is both very prevalent in the rails-community and also the source of most problems. I.e. when you watch any random RailsCast it is usually filled to the rim with obscure incantations and "look how we need only one LoC to perform $excessive_magic"! The end-result are those deeply entangl…
steer clear from most of the entrenched practices and packages (e.g. devise and related trainwrecks) I agree with your sentiment in general, but what do you suggest to use in place of devise? Surely you're not suggesting to write all the code for handling mail confirmation, password changes etc. yourself?
Re: Where the logic hides in rails apps
#28This is the sanest Rails design-advice that I've read in a long time. It counters the misguided "implicit over explicit"-mantra that is both very prevalent in the rails-community and also the source of most problems. I.e. when you watch any random RailsCast it is usually filled to the rim with obscure incantations and "look how we need only one LoC to perform $excessive_magic"! The end-result are those deeply entangl…
steer clear from most of the entrenched practices and packages (e.g. devise and related trainwrecks) I agree with your sentiment in general, but what do you suggest to use in place of devise? Surely you're not suggesting to write all the code for handling mail confirmation, password changes etc. yourself?
Furthermore you usually end up heavily customizing whatever auth-code you start with anyway. The shrinkwrapped gems never cover even half of what an app eventually needs. Thus another advantage is that you won't have to reverse engineer devise or authlogic when you arrive at that point (and trust me, you really don't want to look at their code and the SQL they emit).
That all said, in a recent project I've found the 'sorcery'-gem to provide a reasonable baseline for rolling your own. It's one of the first "second generation" Rails-gems that refrain from most of the magic and instead provide a set of primitives that you wire up yourself.
It still suffers from a bit of rails-smell (code-generators...), but overall the level of abstraction looks about right.
Re: Where the logic hides in rails apps
#29I'll give a proposal now: every chair of every developer shall from now on give them electric shock whenever they use the term "business logic". Ouch. Seriously, "CreatesContact" is not really a class. It's a procedure, function with side effects, whatever you call it. Just with a class wrapper that boosts the developer ego almost as much as an AbstractFactoryManagerFactory. No, modules are actually great. If you hav…
> give them electric shock even better, force them to use COmmon Business Oriented Language
Re: Where the logic hides in rails apps
#30To be honest; it looks like this post might have been inspired by that book (or the concepts behind it) but I think the book does a better job explaining it (Obviously, a book vs a single blog post.)